<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2230386454320727695</id><updated>2024-09-04T13:20:17.306-07:00</updated><category term="code"/><title type='text'>MCTS .NET Certification Station</title><subtitle type='html'>Covers topics on the Microsoft Certification Exam for the .NET Framework (Exam 70-536, Microsoft .NET Framework - Application Development Foundation)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default?start-index=26&amp;max-results=25'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-2726129205192571734</id><published>2009-02-07T10:16:00.000-08:00</published><updated>2009-02-07T13:52:01.251-08:00</updated><title type='text'>Calling unmanaged code from C#</title><content type='html'>One of the objectives of &lt;span id=&quot;labelAboutExam&quot;&gt;&lt;span class=&quot;DetailPagesContentText&quot;&gt;Exam 70-536 is&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot; class=&quot;DetailPagesContentHeading1&quot;&gt;Implementing interoperability, reflection, and mailing functionality in a .NET Framework application&lt;/span&gt;&lt;br /&gt;&lt;ul class=&quot;DetailPagesContentUnorderedList&quot;&gt;&lt;li class=&quot;DetailPagesContentListItem&quot;&gt;&lt;span&gt;&lt;div class=&quot;Abstract&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Call unmanaged DLL functions within a .NET Framework application, and control the marshalling of data in a .NET Framework application.&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;There are several subtopics in this requirement. The example presented today will cover&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;ul class=&quot;DetailPagesContentUnorderedList&quot;&gt;&lt;li class=&quot;DetailPagesContentListItem&quot;&gt;&lt;span&gt;&lt;div class=&quot;Abstract&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create a class to hold DLL functions;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;DetailPagesContentListItem&quot;&gt;&lt;span&gt;&lt;div class=&quot;Abstract&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create prototypes in managed code&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;DetailPagesContentListItem&quot;&gt;&lt;span&gt;&lt;div class=&quot;Abstract&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Call a DLL function&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;DetailPagesContentListItem&quot;&gt;&lt;span&gt;&lt;div class=&quot;Abstract&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Call a DLL function in special cases, such as passing structures and implementing callback functions&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;Many interop examples seem to cover the simplistic case of hello world in a dialog. But the real challenge when calling unmanaged code involves the marshaling data between the two memory spaces.  While writing this example I had a few headaches with access violations (unmanaged code going farther than allowed) and a few marshaling errors.  Everything was erroring around the lpCustColors array.  In the Win32 definition it is listed as a pointer (to an array of COLORREF structures)&lt;br /&gt;&lt;br /&gt;Rather than declare the array in managed space and marshal it over, it proved far easier to allocate and fill the array in the unmanaged space. The example below shows how to call the native ColorChooser dialog. The color chooser dialog requires a specific structure to be populated before it is called.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Calling unmanaged code from C# Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;namespace InteropExample&lt;br /&gt;{&lt;br /&gt;    public class Win32&lt;br /&gt;    {&lt;br /&gt;        [DllImport(&quot;comdlg32.dll&quot;)]&lt;br /&gt;        public static extern bool ChooseColor(CHOOSECOLOR pChooseColor);&lt;br /&gt;&lt;br /&gt;        [DllImport(&quot;Kernel32.dll&quot;)]&lt;br /&gt;        public static extern IntPtr LocalAlloc(int flags, int size);&lt;br /&gt;&lt;br /&gt;        [DllImport(&quot;Kernel32.dll&quot;)]&lt;br /&gt;        public static extern int LocalFree(IntPtr addr);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    [StructLayoutAttribute(LayoutKind.Sequential)]&lt;br /&gt;    public class CHOOSECOLOR:IDisposable&lt;br /&gt;    {&lt;br /&gt;        public Int32 lStructSize;&lt;br /&gt;        public IntPtr hwndOwner;&lt;br /&gt;        public IntPtr hInstance;&lt;br /&gt;        public Int32 rgbResult;&lt;br /&gt;        public IntPtr lpCustColors;&lt;br /&gt;        public uint Flags;&lt;br /&gt;        public Int32 lCustData = 0;&lt;br /&gt;        public IntPtr lpfnHook;&lt;br /&gt;        public IntPtr lpTemplateName;&lt;br /&gt;&lt;br /&gt;        public CHOOSECOLOR()&lt;br /&gt;        {&lt;br /&gt;            lStructSize = System.Runtime.InteropServices.Marshal.SizeOf(this);&lt;br /&gt;            hwndOwner = IntPtr.Zero;&lt;br /&gt;            hInstance = IntPtr.Zero;&lt;br /&gt;            rgbResult = 0; //black&lt;br /&gt;            lpCustColors = Win32.LocalAlloc(64, 64);&lt;br /&gt;            //Fill up some random custom colors, just to show we can write to unmanaged memory&lt;br /&gt;            for(int i = 0; i &lt;16; i++)&lt;br /&gt;            {&lt;br /&gt;                System.Runtime.InteropServices.Marshal.WriteInt32((IntPtr)(lpCustColors), sizeof(UInt32) * i, 0x0004937E &lt;&lt; i);&lt;br /&gt;            }&lt;br /&gt;            Flags = 0;&lt;br /&gt;            lCustData = 0;&lt;br /&gt;            lpfnHook = IntPtr.Zero;&lt;br /&gt;            lpTemplateName = IntPtr.Zero;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public virtual void Dispose()&lt;br /&gt;        {&lt;br /&gt;            Win32.LocalFree(lpCustColors);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            CHOOSECOLOR chooseColorData = new CHOOSECOLOR();&lt;br /&gt;            Win32.ChooseColor(chooseColorData);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Results&lt;/span&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://www.spunkysoftware.com/download/color-chooser-interop-result.JPG&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 354px; height: 348px;&quot; src=&quot;http://www.spunkysoftware.com/download/color-chooser-interop-result.JPG&quot; alt=&quot;&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/42b9ea93.aspx&quot;&gt;.NET Platform Invoke Examples&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms646912%28VS.85%29.aspx&quot;&gt;Win32 ChooseColor Function&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://www.codeproject.com/KB/dotnet/Win32APICPlusPlustoDotNET.aspx&quot;&gt;Win32 Type Mapping between C++ and C#&lt;/a&gt; (Code Project)&lt;/span&quot;font-weight:&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/2726129205192571734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/2726129205192571734' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2726129205192571734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2726129205192571734'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2009/02/calling-unmanaged-code-from-c.html' title='Calling unmanaged code from C#'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-278399074911597783</id><published>2008-12-06T01:12:00.000-08:00</published><updated>2008-12-06T01:44:58.309-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>Regular Expression Vowel Counter</title><content type='html'>&lt;span class=&quot;DetailPagesContentHeading1&quot;&gt;In this example we are going to touch on two objectives of the 70-536 exam.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span&gt;Regex class&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;MatchCollection class&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;DetailPagesContentHeading1&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Implementing serialization and input/output functionality in a .NET Framework application&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span&gt;FileStream class&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;StreamReader class&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span&gt;To show these classes in use we are going to count the number of vowels in 25 popular search terms (popular according to Lycos) These strings are included in a link in the resources.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Regex and File Stream Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;namespace SimpleRegExExample&lt;br /&gt;{&lt;br /&gt;   class Program&lt;br /&gt;   {&lt;br /&gt;       static void Main(string[] args)&lt;br /&gt;       {&lt;br /&gt;           // In this example we are going to hit two exam points,&lt;br /&gt;           // using a file stream and using a regular expression.&lt;br /&gt;           // This example only touches on the use of regular&lt;br /&gt;           // expressions... in fact there are whole books on the subject&lt;br /&gt;           // as it can be cosidered a language it self. Feel free&lt;br /&gt;           // to comment on specific regular expressions you want&lt;br /&gt;           // to see examples on.&lt;br /&gt;&lt;br /&gt;           //Match only the vowels...&lt;br /&gt;           Regex vowels = new Regex(&quot;[aeiou]&quot;, RegexOptions.IgnoreCase | RegexOptions.Compiled);&lt;br /&gt;           MatchCollection mc;&lt;br /&gt;           FileStream fs = null;&lt;br /&gt;           StreamReader reader = null; ;&lt;br /&gt;           String current_line;&lt;br /&gt;&lt;br /&gt;           // A filestream can throw a number of exceptions if the file&lt;br /&gt;           // you use to create it can&#39;t be found or accessed ( such as&lt;br /&gt;           // security reasons, a disc error, etc)&lt;br /&gt;&lt;br /&gt;           try&lt;br /&gt;           {&lt;br /&gt;               // For this example we are reading in a text file with 25 lines of text.&lt;br /&gt;               // It&#39;s hard to make up that much data, so I just took the top 26-50&lt;br /&gt;               // search terms on lycos and placed them in a text file. Some of the terms&lt;br /&gt;               // were kind of racy, like &quot;Kendra Wilkinson Playboy Playmate&quot;...&lt;br /&gt;               // If you stumbled here hoping to find pictures of said search term, this&lt;br /&gt;               // is the wrong place.&lt;br /&gt;               fs = new FileStream(&quot;lycos_top_search_terms_26_to_50.txt&quot;,FileMode.Open);&lt;br /&gt;              &lt;br /&gt;               //Life is easier when we wrap the filestream ina stream reader,&lt;br /&gt;               // then we don&#39;t have to code the buffering for read line operations&lt;br /&gt;               reader = new StreamReader(fs);&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;           // This is bad, you really should catch specific exceptions...&lt;br /&gt;           // but we skip it for this example.&lt;br /&gt;           catch (Exception e)&lt;br /&gt;           {&lt;br /&gt;               Console.Out.WriteLine(e.Message);&lt;br /&gt;               Console.Out.WriteLine(e.StackTrace);&lt;br /&gt;               if (reader != null)&lt;br /&gt;               {&lt;br /&gt;                   reader.Close();&lt;br /&gt;               }&lt;br /&gt;               if (fs != null)&lt;br /&gt;               {&lt;br /&gt;                   fs.Close();&lt;br /&gt;               }&lt;br /&gt;               return;&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;           while (!reader.EndOfStream)&lt;br /&gt;           {&lt;br /&gt;               current_line = reader.ReadLine();&lt;br /&gt;               mc = vowels.Matches(current_line);&lt;br /&gt;&lt;br /&gt;               // The match collect now contains the results of running the regular&lt;br /&gt;               // against the line we read in from the file&lt;br /&gt;               Console.Out.WriteLine(&quot;The search term \&quot;&quot; + current_line + &quot;\&quot; has &quot; + mc.Count + &quot; vowels in it&quot;);&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;           //Close the reader first&lt;br /&gt;           reader.Close();&lt;br /&gt;           //Now close the file&lt;br /&gt;           fs.Close();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Output&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size:78%;&quot;&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Flickr Picture&quot; has 4 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Brooke Burke Dancing star&quot; has 8 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Kendra Wilkinson Playboy Playmate&quot; has 10 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Julianne Hough Watching stars&quot; has 9 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Twilight Vampire movie out now&quot; has 11 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Lindsay Lohan Relatively quiet week&quot; has 13 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Holly Madison Playboy Playmate #2&quot; has 9 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Black Friday Look for your local ad&quot; has 11 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Harry Potter New movie in the works&quot; has 10 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Weight Watchers Getting ready for the new year&quot; has 13 vowels i&lt;/span&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;n it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Carmen Electra Taking it slow&quot; has 9 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Jessica Alba New Mom&quot; has 7 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Limewire Download site&quot; has 9 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Fox News National new coverage&quot; has 11 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Lowes Do-it-yourself&quot; has 7 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Santa Claus Coming to town&quot; has 8 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Beyonce Knowles Is Sasha Fierce&quot; has 11 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Home Depot The Lumberyard&quot; has 8 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Paula Abdul Leaving American Idol?&quot; has 14 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;US Postal Service Holiday Packages &quot; has 12 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Jennifer Lopez Keeping it quiet&quot; has 12 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Haley Joel Osment On Broadway&quot; has 10 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Lil Wayne New CD release&quot; has 8 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Angelina Jolie Mom again?&quot; has 11 vowels in it&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The search term &quot;Plentyoffish.com Dating site&quot; has 8 vowels in it&lt;/span&gt;&lt;/blockquote&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;br /&gt;Additional Resources&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/28hw3sce%28VS.80%29.aspx&quot;&gt;Introductions to Regular Expressions&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx&quot;&gt;FileStream Class&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx&quot;&gt;StreamReader Class&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://www.radsoftware.com.au/regexdesigner/&quot;&gt;Regular Expression Designer&lt;/a&gt; (Rad Software, a must have for non trivial regular expression testing)&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;http://www.spunkysoftware.com/download/lycos_top_search_terms_26_to_50.txt&quot;&gt;Test File&lt;/a&gt; used in this example&lt;br /&gt;&lt;br /&gt;non code related...&lt;br /&gt;&lt;a href=&quot;http://50.lycos.com/&quot;&gt;Lycos top 50 search terms&lt;/a&gt; (Lycos)&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/278399074911597783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/278399074911597783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/278399074911597783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/278399074911597783'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/12/regular-expression-vowel-counter.html' title='Regular Expression Vowel Counter'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-3817446385104205081</id><published>2008-11-24T22:59:00.000-08:00</published><updated>2008-11-24T23:28:12.236-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>The December 21, 2012 Date Formatting Example</title><content type='html'>One of the objectives in Exam 70-536 is to ensure knowledge formatting dates.  Specifically in the&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;DetailPagesContentHeading1&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application&lt;/span&gt; section, we see&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span&gt;Format date and time values based on the culture&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span&gt;&lt;br /&gt;The .NET framework makes this task pretty straight forward with the System.Globalization namespace.  Within this name space there is the CultureInfo class.  The CultureInfo class contains all of the specific formatting rules for a specific culture.  Cultures are divided up by language and region.&lt;br /&gt;&lt;br /&gt;So to exercise this objective we print out a date in five different culture specific formats.  We pick the date December 21, 2012, the end of the Mayan calendar as a fun date to use. Links are provided below about this date if you want to see what all of the buzz is about. But onto the code sample&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Date Formatted Based on Culture Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Globalization;&lt;br /&gt;&lt;br /&gt;namespace DateTimeFormatExample&lt;br /&gt;{&lt;br /&gt;   class Program&lt;br /&gt;   {&lt;br /&gt;       static void Main(string[] args)&lt;br /&gt;       {&lt;br /&gt;           //This example is going to show how to format&lt;br /&gt;           // a date for several cultures. We could pick&lt;br /&gt;           // any date for this example, but just for kicks&lt;br /&gt;           // we&#39;ll pick December 21, 2012. This date is&lt;br /&gt;           // mysterious to astrologists and conspiracy&lt;br /&gt;           // theorists because it is the end of the Mayan&lt;br /&gt;           // calandar... will it be THE end? Who knows, but&lt;br /&gt;           // we&#39;ll use it here for our example.&lt;br /&gt;&lt;br /&gt;           // Declare the date December 21, 2012&lt;br /&gt;           DateTime dt = new DateTime(2012, 12, 21, 4, 0, 0);&lt;br /&gt;&lt;br /&gt;           //First let&#39;s print out for US English&lt;br /&gt;           CultureInfo en_us_ci = new CultureInfo(&quot;en-US&quot;);&lt;br /&gt;           //Print short date format&lt;br /&gt;           Console.WriteLine(&quot;US English &quot; + dt.ToString(&quot;d&quot;, en_us_ci));&lt;br /&gt;&lt;br /&gt;           //Next let&#39;s print out for Chinese, PRC&lt;br /&gt;           CultureInfo zh_cn_ci = new CultureInfo(&quot;zh-CN&quot;);&lt;br /&gt;           Console.WriteLine(&quot;Chinese, PRC &quot; + dt.ToString(&quot;d&quot;, zh_cn_ci));&lt;br /&gt;&lt;br /&gt;           //Next let&#39;s print out for German (Germany)&lt;br /&gt;           CultureInfo de_de_ci = new CultureInfo(&quot;de-DE&quot;);&lt;br /&gt;           Console.WriteLine(&quot;German (Germany) &quot; + dt.ToString(&quot;d&quot;, de_de_ci));&lt;br /&gt;&lt;br /&gt;           //Next let&#39;s print out for Hebrew (Israel)&lt;br /&gt;           CultureInfo he_il_ci = new CultureInfo(&quot;he-IL&quot;);&lt;br /&gt;           Console.WriteLine(&quot;Hebrew (Israel) &quot; + dt.ToString(&quot;d&quot;, he_il_ci));&lt;br /&gt;&lt;br /&gt;           //Next let&#39;s print out for Punjabi (India)&lt;br /&gt;           CultureInfo pa_in_ci = new CultureInfo(&quot;pa-IN&quot;);&lt;br /&gt;           Console.WriteLine(&quot;Punjabi (India) &quot; + dt.ToString(&quot;d&quot;, pa_in_ci));&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Date Format Example Output&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;US English 12/21/2012&lt;br /&gt;Chinese, PRC 2012/12/21&lt;br /&gt;German (Germany) 21.12.2012&lt;br /&gt;Hebrew (Israel) 21/12/2012&lt;br /&gt;Punjabi (India) 21-12-12&lt;/blockquote&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx&quot;&gt;CultureInfo Class&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Non code related...&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/2012&quot;&gt;2012&lt;/a&gt; (Wikipedia)&lt;br /&gt;&lt;a href=&quot;http://www.survive2012.com/&quot;&gt;Survive 2012&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/3817446385104205081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/3817446385104205081' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3817446385104205081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3817446385104205081'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/11/december-21-2012-date-formatting.html' title='The December 21, 2012 Date Formatting Example'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-1020197425407215913</id><published>2008-10-21T00:04:00.000-07:00</published><updated>2008-10-21T00:27:09.152-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>How do I retrieve information about the current process using C#?</title><content type='html'>I can think of many occasions when I have been diagnosing an issue on a customer machine and I find myself opening the task manager to gather valuable information about the application under question.  If the customer will allow it, I will usually take the task manager one step further and use the &lt;a href=&quot;http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx&quot;&gt;Process Explorer from SysInternals&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But there has to be a better way, your application should be able to grab that information without using another application. And in fact it can by using the System.Diagnostics namespace. Conveniently this is also a requirement on the 70-536 exam in the &quot;&lt;span&gt;Manage system processes and monitor the performance of a .NET application by using the diagnostics functionality of the .NET Framework.&quot; section. Specifically the objective is to:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&quot;Retrieve information about the current process&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is made possible by the Process class within the System.Diagnostics class. Before we get into the code sample, it should be noted that a Process has a number of attributes. Many of these attributes are omitted to keep it short and sweet. Refer to the docs for the full list of Process attributes.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Current Process Info Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;&lt;br /&gt;namespace CurrentProcessInfo&lt;br /&gt;{&lt;br /&gt;  class Program&lt;br /&gt;  {&lt;br /&gt;      static void Main(string[] args)&lt;br /&gt;      {&lt;br /&gt;          //First lets get our parent process&lt;br /&gt;          Process my_process = Process.GetCurrentProcess();&lt;br /&gt;&lt;br /&gt;          // Now we&#39;ll spit out some pertinent info on our process&lt;br /&gt;          // Only a handful of the properties are referred to here,&lt;br /&gt;          // see the docs for the full list&lt;br /&gt;          Console.WriteLine(&quot;\nThe current process has the following attributes:&quot;);&lt;br /&gt;          Console.WriteLine(&quot;------------------------------------&quot;);&lt;br /&gt;          Console.WriteLine(&quot;Process Name: &quot; + my_process.ProcessName);&lt;br /&gt;          Console.WriteLine(&quot;Window Title: &quot; + my_process.MainWindowTitle);&lt;br /&gt;          Console.WriteLine(&quot;Running on: &quot; + my_process.MachineName);&lt;br /&gt;          Console.WriteLine(&quot;Priority: &quot; + my_process.PriorityClass.ToString());&lt;br /&gt;          Console.WriteLine(&quot;Responding: &quot; + my_process.Responding);&lt;br /&gt;          Console.WriteLine(&quot;Virtual Memory: &quot; + my_process.VirtualMemorySize64);&lt;br /&gt;          Console.WriteLine(&quot;------------------------------------&quot;);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx&quot;&gt;Process&lt;/a&gt; Class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx&quot;&gt;System.Diagnostics&lt;/a&gt; Namespace (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/1020197425407215913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/1020197425407215913' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1020197425407215913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1020197425407215913'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/10/how-do-i-retrieve-information-about.html' title='How do I retrieve information about the current process using C#?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-1255091840235220965</id><published>2008-10-20T22:18:00.000-07:00</published><updated>2008-10-20T23:32:11.505-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>Set a break point through code with C#</title><content type='html'>If you have spent time debugging, you probably know you can click any code line to add a break point. If you have spent some more time you have probably even figured out how to set conditional breakpoints, as Sara Ford explains in this &quot;&lt;a href=&quot;http://blogs.msdn.com/saraford/archive/2008/06/17/did-you-know-you-can-set-conditional-breakpoints-239.aspx&quot;&gt;tip of the day&lt;/a&gt;&quot;.&lt;br /&gt;&lt;br /&gt;But did you know you can also cause a break point to trigger from within your code? It is actually pretty easy using the Debugger class within the System.Diagnostics name space. I learned about the Debugger class while looking over the specifics for the &quot;&lt;span&gt;Debug and trace a .NET Framework application by using the System.Diagnostics namespace.&quot; section of the 70-536 exam.&lt;br /&gt;&lt;br /&gt;If this code is run outside of the debugger, the OS will ask you if you would like to debug the process.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Debugger Break form Code Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;namespace BreakFromCodeExample&lt;br /&gt;{&lt;br /&gt;   class Program&lt;br /&gt;   {&lt;br /&gt;       static void Main(string[] args)&lt;br /&gt;       {&lt;br /&gt;           Console.WriteLine(&quot;Thing are going fine...&quot;);&lt;br /&gt;           Console.WriteLine(&quot;then something goes wrong and we want to break&quot;);&lt;br /&gt;           Console.WriteLine(&quot;so we can investigate further...&quot;);&lt;br /&gt;          &lt;br /&gt;           //This is the call that fires the break point event&lt;br /&gt;           System.Diagnostics.Debugger.Break();&lt;br /&gt;&lt;br /&gt;           Console.WriteLine(&quot;You are now free to place break points with or without a GUI.&quot;);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.aspx&quot;&gt;Debugger&lt;/a&gt; Class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx&quot;&gt;System.Diagnostics&lt;/a&gt; Namespace (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/1255091840235220965/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/1255091840235220965' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1255091840235220965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1255091840235220965'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/10/set-break-point-through-code-with-c.html' title='Set a break point through code with C#'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-3532839607037263189</id><published>2008-10-20T21:52:00.000-07:00</published><updated>2008-10-20T22:11:17.354-07:00</updated><title type='text'>Implemeting the IConfigurationSystem Interface</title><content type='html'>After a long hiatus... getting back in the writing zone....&lt;br /&gt;&lt;br /&gt;Within the &quot;&lt;span class=&quot;DetailPagesContentHeading1&quot;&gt;Embedding configuration, diagnostic, management, and installation features into a .NET Framework application&quot; section of Exam 70-536 we are instructed to &quot;Implement IConfigurationSystem Interface&quot;.&lt;br /&gt;&lt;br /&gt;This seemed like a fairly straight forward task so I immediately looked up the interface in the MSDN docs.  However, upon reading about the interface, I think someone goofed.  The documentation specifically says that the IConfigurationSystem Interface &quot;&lt;/span&gt;supports the .NET Framework infrastructure and is not intended to be used directly from your code.&quot;&lt;br /&gt;&lt;br /&gt;So maybe we don&#39;t need to know too much about this interface after all.  Just in case the error is on the side of the documentation, you need to implement two methods to support the IConfigurationSystem Interface&lt;br /&gt;&lt;ul&gt;&lt;li&gt;GetConfig&lt;/li&gt;&lt;li&gt;Init&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;GetConfig&lt;/span&gt;&lt;/span&gt; returns an object and takes configKey (String) as a parameter.&lt;br /&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;Init&lt;/span&gt;&lt;/span&gt; returns void and takes no parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.configuration.iconfigurationsystem.aspx&quot;&gt;IConfigurationSystem Interface&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/3532839607037263189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/3532839607037263189' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3532839607037263189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3532839607037263189'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/10/implemeting-iconfigurationsystem.html' title='Implemeting the IConfigurationSystem Interface'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-2531938528730027984</id><published>2008-05-24T15:17:00.000-07:00</published><updated>2008-09-21T16:37:54.733-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>How Do You Retrieve Information About All Network Connections?</title><content type='html'>One of the objectives of the MCTS .NET Framework exam is to&lt;br /&gt;&lt;br /&gt;&lt;blockquote style=&quot;font-style: italic;&quot;&gt;Embed management information and events into a .NET Framework application. (Refer System.Management namespace)&lt;/blockquote&gt;&lt;br /&gt;and within that exam objective there is the specific objective&lt;br /&gt;&lt;br /&gt;&lt;blockquote style=&quot;font-style: italic;&quot;&gt;Retrieve information about all network connections.&lt;/blockquote&gt;&lt;br /&gt;I started to look through the System.Management namespace and found the ManagementObject and the ManagementObjectSearcher.  Then the clarity of the examples of the descriptions and examples began to muddy.  I understood that the ManagementObjectSearcher was using an ObjectQuery object to perform the search.  It was completely unclear WHAT was being queried.&lt;br /&gt;&lt;br /&gt;My investigations then lead me to the Windows Management Interface, known as WMI.  What does this have to do with ObjectQuery and the ManagementObjectSearcher classes?  Well, WMI and the underlying WMI classes are what is actually being queried.  The queries are written in a SQL derivative named WQL.  There is a dizzying variety of information exposed by WMI.&lt;br /&gt;&lt;br /&gt;After the mechanics of writing a query are understood, the next task is to find the correct WMI class that encapsulates the information you need. In the case of our question at hand, we are looking for networking information.&lt;br /&gt;&lt;br /&gt;At first I was happy to find the Win32_NetworkConnection class, but found that it did not return information for me. (Despite having a connection up for writing this post).  The next promising class was the Win32_NetworkAdapter class.  Using this class I created the example below that retrieves information about all network connections.&lt;br /&gt;&lt;br /&gt;A &quot;gotcha&quot; to consider before reviewing the code below:&lt;br /&gt;My first version of the code listed a number of adapters. I then determined that it listed physical AND logical network adapters.  You will see an if block in the code to distinguish between physical and logical adapters.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Retrieve Information About All Network Connections Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot; &gt;&lt;br /&gt;using System;&lt;br /&gt;// A reference to the System.Management assembly needs&lt;br /&gt;// to be added to your project...&lt;br /&gt;using System.Management;&lt;br /&gt;&lt;br /&gt;namespace NetworkConnectionsExample&lt;br /&gt;{&lt;br /&gt;  class Program&lt;br /&gt;  {&lt;br /&gt;      static void Main(string[] args)&lt;br /&gt;      {&lt;br /&gt;          // In order to use ManagementObjectSearcher, we need to&lt;br /&gt;          // supply an query string to search on.  We are searching&lt;br /&gt;          // against differenct classes exposed by the Windows Management&lt;br /&gt;          // Interface(WMI).&lt;br /&gt;          ManagementObjectSearcher network_connections =&lt;br /&gt;          new ManagementObjectSearcher(&lt;br /&gt;              &quot;SELECT * FROM Win32_NetworkAdapter&quot;);&lt;br /&gt;&lt;br /&gt;          Console.WriteLine(&quot;\nFirst we will just list the names of all physical adapters&quot;);&lt;br /&gt;          Console.WriteLine(&quot;and their connection status&quot;);&lt;br /&gt;          Console.WriteLine(&quot;-----------------------------&quot;);&lt;br /&gt;        &lt;br /&gt;          // The query of the underlying ObjectQuery object is not executed&lt;br /&gt;          // until the Get() function is executed.&lt;br /&gt;          foreach (ManagementObject connection in network_connections.Get())&lt;br /&gt;          {&lt;br /&gt;              // Knowledge by experiment... on my machine there were a number&lt;br /&gt;              // of network adapters displayed on my first version of this code.&lt;br /&gt;              // I know I only have three pyhisical adapters (Wireless, 10/100,&lt;br /&gt;              // and 1394) so I empirically determined that the Management Objects&lt;br /&gt;              // with the NetConnectionStatus property were physical apdapters and&lt;br /&gt;              // not logical adapters... mileage may vary, results not insured ;)&lt;br /&gt;              if (connection.Properties[&quot;NetConnectionStatus&quot;].Value != null)&lt;br /&gt;              {&lt;br /&gt;                  Console.WriteLine(&quot;Product Name: &quot; + connection.Properties[&quot;ProductName&quot;].Value);&lt;br /&gt;                  Console.WriteLine(&quot;Connection Status: &quot; + connection.Properties[&quot;NetConnectionStatus&quot;].Value);&lt;br /&gt;                  Console.WriteLine(&quot;-----------------------------&quot;);&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          Console.WriteLine(&quot;\nNext we will show all of the information availalbe for each physical adapter.&quot;);&lt;br /&gt;          Console.WriteLine(&quot;Probably more than you ever wanted to know about your network adapter, but your software might need to know it...&quot;);&lt;br /&gt;          Console.WriteLine(&quot;-----------------------------&quot;);&lt;br /&gt;&lt;br /&gt;          foreach (ManagementObject connection in network_connections.Get())&lt;br /&gt;          {&lt;br /&gt;              if (connection.Properties[&quot;NetConnectionStatus&quot;].Value != null)&lt;br /&gt;              {&lt;br /&gt;                  foreach (PropertyData d in connection.Properties)&lt;br /&gt;                  {&lt;br /&gt;                      Console.WriteLine(&quot;-- Name: &quot; + d.Name + &quot; Value: &quot; + d.Value);&lt;br /&gt;                  }&lt;br /&gt;                  Console.WriteLine(&quot;-----------------------------&quot;);&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.management.managementobjectsearcher.aspx&quot;&gt;ManagementObjectSearcher&lt;/a&gt; class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa392727%28VS.85%29.aspx&quot;&gt;WMI Operating System Classes&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa394216%28VS.85%29.aspx&quot;&gt;Win32_NetworkAdapter&lt;/a&gt; class (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/2531938528730027984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/2531938528730027984' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2531938528730027984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2531938528730027984'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/05/how-do-you-retrieve-information-about.html' title='How Do You Retrieve Information About All Network Connections?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-8966462335077396912</id><published>2008-05-22T23:57:00.000-07:00</published><updated>2008-09-21T16:39:06.133-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>How can I read an EventLog?</title><content type='html'>Perhaps you have a need to read from a system event log. Perhaps you have even found the System.Diagnostics namespace.  Upon inspecting the EventLog class you will notice a &quot;Write&quot; method but the absence of a complimentary &quot;Read&quot; operation. You are not going crazy, there really isn&#39;t a read method.&lt;br /&gt;&lt;br /&gt;Instead you need to understand a little more about the EventLog object.  The entire contents of an EventLog are read in when the EventLog is constructed (if the variant with a logname is used) or when the Log property is set for the object.  The results of reading the event log are stored in the Entries property.  The entries property is a collection of EventLogEntry objects.  If you would like to see the contents of a particular EventLogEntry, you need &quot;massage&quot; the object a little more by accessing specific properties of the EventLogEntry class.&lt;br /&gt;&lt;br /&gt;It is important to note that the Entries property is a read only property.  You can&#39;t change the contents of the event log by modifying the Entries property.  In order to change the event log, you need to use the &quot;Write&quot; methods.&lt;br /&gt;&lt;br /&gt;The example below shows how to access the 10 most recent log entries from the System event log.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;System Event Log Read Example&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;&lt;br /&gt;namespace ReadEventLogExample&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            // There are three default event logs, Application, System and Security&lt;br /&gt;            EventLog systemLog = new EventLog(&quot;System&quot;);&lt;br /&gt;            // The entries member contains all the entries in the event log&lt;br /&gt;            // There is no need to perform a specific read operation on the event log&lt;br /&gt;            // The Entries member is read only, so you will need to use the write&lt;br /&gt;            // methods if you want to write to the EventLog&lt;br /&gt;            int entryCount = systemLog.Entries.Count;&lt;br /&gt;            entryCount = entryCount - 1; //We are using the count for a zero based index...&lt;br /&gt;&lt;br /&gt;            Console.WriteLine(&quot;The last 10 entries in the System event log&quot;);&lt;br /&gt;&lt;br /&gt;            for (int i = 0; i &lt; 10; i++)&lt;br /&gt;            {&lt;br /&gt;                if (entryCount - i &gt;= 0) //We only want positive indexes...&lt;br /&gt;                {&lt;br /&gt;                    Console.WriteLine(&quot;------------------------------------\n&quot;);&lt;br /&gt;                    Console.WriteLine(&quot;Time Generated: &quot; + systemLog.Entries[entryCount - i].TimeGenerated);&lt;br /&gt;                    Console.WriteLine(&quot;Time Written: &quot; + systemLog.Entries[entryCount - i].TimeWritten);&lt;br /&gt;                    Console.WriteLine(&quot;Source: &quot; + systemLog.Entries[entryCount - i].Source);&lt;br /&gt;                    Console.WriteLine(&quot;Entry Type: &quot; + systemLog.Entries[entryCount - i].EntryType);&lt;br /&gt;                    Console.WriteLine(&quot;Message: &quot; + systemLog.Entries[entryCount - i].Message + &quot;\n&quot;);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx&quot;&gt;EventLog&lt;/a&gt; Class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogentry_members.aspx&quot;&gt;EventLogEntry&lt;/a&gt; Class (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/8966462335077396912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/8966462335077396912' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8966462335077396912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8966462335077396912'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/05/how-can-i-read-eventlog.html' title='How can I read an EventLog?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-8773281012002917260</id><published>2008-05-22T15:00:00.000-07:00</published><updated>2008-09-21T16:39:51.790-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>What is the difference between byte and Byte in the .NET Framework?</title><content type='html'>Have you ever started to type &#39;by&#39; while writing code in Visual Studio and seen both an upper case and lower case &quot;byte&quot; in the intellisense menu and wondered what the difference was?&lt;br /&gt;&lt;br /&gt;Lower case &quot;byte&quot; is a built in type in C#. System.Byte is a class built into the .NET framework that represents a byte. The secret is that this built in type is an alias to the System.Byte class. Different .NET languages have different aliases based on the semantics of the particular language, but they all map to specific object types in the .NET framework. This allows code to be written more &quot;cleanly&quot; and still easily compile to the correct type in the .NET framework.&lt;br /&gt;&lt;br /&gt;Let&#39;s confirm the statement that the C# built in type &#39;byte&#39; is really an alias of the System.Byte class.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;byte and System.Byte Example&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;c-sharp:nogutter&quot; name=&quot;code&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;namespace ByteDifferenceExample&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            byte small_b_byte = 1;&lt;br /&gt;            Byte large_b_byte = 2;&lt;br /&gt;      &lt;br /&gt;            Console.WriteLine(&quot;The value of the little b byte is: &quot; + small_b_byte);&lt;br /&gt;            Console.WriteLine(&quot;The type of the little b byte is: &quot; + small_b_byte.GetType());&lt;br /&gt;&lt;br /&gt;            Console.WriteLine(&quot;----------------------------&quot;);&lt;br /&gt;&lt;br /&gt;            Console.WriteLine(&quot;The value of the big b byte is: &quot; + large_b_byte);&lt;br /&gt;            Console.WriteLine(&quot;The type of the big b byte is: &quot; + large_b_byte.GetType());&lt;br /&gt;&lt;br /&gt;            Console.WriteLine(&quot;----------------------------&quot;);&lt;br /&gt;&lt;br /&gt;            if (small_b_byte.GetType() == large_b_byte.GetType())&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&quot;Summary: byte and Byte have the same type!&quot;);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&quot;Summary: byte and Byte have different types&quot;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;Output of byte and System.Byte Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The value of the little b byte is: 1&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The type of the little b byte is: System.Byte&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;----------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The value of the big b byte is: 2&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;The type of the big b byte is: System.Byte&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;----------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;Summary: byte and Byte have the same type!&lt;/span&gt;&lt;/blockquote&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ya5y69ds%28VS.80%29.aspx&quot;&gt;Built-In Types Table, C#&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/8773281012002917260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/8773281012002917260' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8773281012002917260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8773281012002917260'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/05/what-is-difference-between-byte-and.html' title='What is the difference between byte and Byte in the .NET Framework?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-5589512730562905312</id><published>2008-05-19T22:18:00.000-07:00</published><updated>2008-05-19T23:20:43.627-07:00</updated><title type='text'>What is a stack good for?</title><content type='html'>A stack is a specialized list &lt;a href=&quot;http://en.wikipedia.org/wiki/Data_structure&quot;&gt;data structure&lt;/a&gt; that enforces LIFO (last in, first out) ordering of data.  Thinking of a stack as a physical stack of plates (and data items as the plates), you can only take the last plate that you added to the stack.&lt;br /&gt;&lt;br /&gt;The stack data structure is among the most useful structures in Computer Science.  Stack usage appears at all levels of programming, from operating system kernels to high level languages like those in the .NET framework.  Saying that a stack is useful is easy to say, but let&#39;s look at some tasks that a stack can be used for:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Stack Usage Examples&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Expression evaluation (i.e. &lt;a href=&quot;http://en.wikipedia.org/wiki/Reverse_Polish_notation&quot;&gt;postfix&lt;/a&gt; evaluation)&lt;/li&gt;&lt;li&gt;Expression parsing (i.e. convert &lt;a href=&quot;http://en.wikipedia.org/wiki/Infix_notation&quot;&gt;infix&lt;/a&gt; to postfix notation)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.sysknowlogy.com/2005/12/24/C+Implementation+For+Balanced+Matches.aspx&quot;&gt;Balanced brace checking&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.scribd.com/doc/5839/Algorithms?query2=design%20chess%20board%20using%20c%23&quot;&gt;Solving search problems&lt;/a&gt; (i.e. crossword puzzle solver, chess playing algorithms)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;In a future posting a detailed example that uses a stack will be provided.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx&quot;&gt;System.Collections.Stack&lt;/a&gt; Class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Stack_%28data_structure%29&quot;&gt;Stacks&lt;/a&gt; (Wikipedia)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/5589512730562905312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/5589512730562905312' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5589512730562905312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5589512730562905312'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/05/what-is-stack-good-for.html' title='What is a stack good for?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-5879766402212591994</id><published>2008-04-14T23:02:00.000-07:00</published><updated>2008-09-21T16:40:40.337-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>How can you sort a list of strings in the .NET Framework?</title><content type='html'>The .NET Framework provides a simple efficient mechanism to sort a list of strings.  The ArrayList class contains a Sort() method that allows the items in the ArrayList to be sorted in ascending order.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;ArrayList Sort Example&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;&lt;br /&gt;// This is an example of using the .NET Framework and the&lt;br /&gt;// Sort() method of the ArrayList class&lt;br /&gt;namespace CollectionSortExample&lt;br /&gt;{&lt;br /&gt;  class Program&lt;br /&gt;  {&lt;br /&gt;      static void Main(string[] args)&lt;br /&gt;      {&lt;br /&gt;          //Let&#39;s fill the ArrayList with some strings&lt;br /&gt;          ArrayList exampleList = new ArrayList();&lt;br /&gt;          exampleList.Add(&quot;C# Video Game Programming&quot;);&lt;br /&gt;          exampleList.Add(&quot;Really Thick Programming Book&quot;);&lt;br /&gt;          exampleList.Add(&quot;1984&quot;);&lt;br /&gt;          exampleList.Add(&quot;Alice in Wonderland&quot;);&lt;br /&gt;&lt;br /&gt;          //Print the list before it is sorted&lt;br /&gt;          Console.WriteLine(&quot;The unsorted list looks like:&quot;);&lt;br /&gt;          foreach (string item in exampleList)&lt;br /&gt;          {&lt;br /&gt;              Console.WriteLine(&quot;- {0}&quot;, item);&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          //Now we can do some &quot;magic&quot; and sort the&lt;br /&gt;          // ArrayList by caling the Sort() method.&lt;br /&gt;          exampleList.Sort();&lt;br /&gt;&lt;br /&gt;          //Print the list after it is sorted&lt;br /&gt;          Console.WriteLine(&quot;\n\nThe sorted list looks like:&quot;);&lt;br /&gt;          foreach (string item in exampleList)&lt;br /&gt;          {&lt;br /&gt;              Console.WriteLine(&quot;- {0}&quot;, item);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Output of ArrayList Sort Example&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;&lt;br /&gt;&lt;blockquote&gt;The unsorted list looks like:&lt;br /&gt;- C# Video Game Programming&lt;br /&gt;- Really Thick Programming Book&lt;br /&gt;- 1984&lt;br /&gt;- Alice in Wonderland&lt;br /&gt;&lt;br /&gt;The sorted list looks like:&lt;br /&gt;- 1984&lt;br /&gt;- Alice in Wonderland&lt;br /&gt;- C# Video Game Programming&lt;br /&gt;- Really Thick Programming Book&lt;/blockquote&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx&quot;&gt;ArrayList&lt;/a&gt; Class (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/5879766402212591994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/5879766402212591994' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5879766402212591994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5879766402212591994'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/04/how-can-you-sort-list-of-strings-in-net.html' title='How can you sort a list of strings in the .NET Framework?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-5013905936272260269</id><published>2008-04-08T21:01:00.000-07:00</published><updated>2008-09-21T16:41:45.141-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>What attribute should you add to a class to allow it to be serialized?</title><content type='html'>A class can be serialized when it has the &quot;Serializable&quot; attribute.  Serialization is the process of storing the contents of an object to long term storage.  If you will only be using .NET Framework based applications to process your serialized objects, then the BinaryFormatter class will be the most efficient.  If you will be transmitting your serialized object across a network or sharing it with a non .NET Application, then the SoapFormatter class should be used to export the object to the XML based SOAP format.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Serialization Example&lt;/span&gt;&lt;br /&gt;Note that you need to add a reference to System.Runtime.Serialization.Formatters.Soap.dll to your project before compiling the code below.  Unlike the BinaryFormatter class, the SoapFormatter class is not included by default.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Runtime.Serialization;&lt;br /&gt;using System.Runtime.Serialization.Formatters.Binary;&lt;br /&gt;using System.Runtime.Serialization.Formatters.Soap;&lt;br /&gt;&lt;br /&gt;namespace SerializationExample&lt;br /&gt;{&lt;br /&gt;[Serializable]&lt;br /&gt;class ObjectToSerialize&lt;br /&gt;{&lt;br /&gt; string sName;&lt;br /&gt; int iCount;&lt;br /&gt; double dPrice;&lt;br /&gt;&lt;br /&gt; public ObjectToSerialize(string newName, int newCount, double newPrice)&lt;br /&gt; {&lt;br /&gt;     sName = newName;&lt;br /&gt;     iCount = newCount;&lt;br /&gt;     dPrice = newPrice;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt; static void Main(string[] args)&lt;br /&gt; {&lt;br /&gt;     ObjectToSerialize o = new ObjectToSerialize(&quot;Video Game&quot;, 1, 50.00);&lt;br /&gt;&lt;br /&gt;     // Create the files to save the data to&lt;br /&gt;     FileStream binary_fs = new FileStream(&quot;Serialization_Example.bin&quot;, FileMode.Create);&lt;br /&gt;     FileStream xml_fs = new FileStream(&quot;Serialization_Example.xml&quot;, FileMode.Create);&lt;br /&gt;&lt;br /&gt;     // Create a BinaryFormatter object to perform the serialization&lt;br /&gt;     BinaryFormatter bf = new BinaryFormatter();&lt;br /&gt;     // Create a SoapFormatter object to perform serialization&lt;br /&gt;     SoapFormatter sf = new SoapFormatter();&lt;br /&gt;&lt;br /&gt;     // Use the BinaryFormatter object to serialize the data to the file&lt;br /&gt;     bf.Serialize(binary_fs, o);&lt;br /&gt;     // Use the SoapFormatter object to serialize the data to the file&lt;br /&gt;     sf.Serialize(xml_fs, o);&lt;br /&gt;&lt;br /&gt;     // Close the files&lt;br /&gt;     binary_fs.Close();&lt;br /&gt;     xml_fs.Close();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Binary Results&lt;/span&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://farm3.static.flickr.com/2354/2399634423_27b2afdea3_o.jpg&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px;&quot; src=&quot;http://farm3.static.flickr.com/2354/2399634423_27b2afdea3_o.jpg&quot; alt=&quot;&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;SOAP Results&lt;/span&gt;&lt;br /&gt;The XML results of the SOAP Serialization can be found here: &lt;a href=&quot;http://www.spunkysoftware.com/download/SerializationExample/Serialization_Example.xml&quot;&gt;SOAP Serialization Results&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx&quot;&gt;BinaryFormatter&lt;/a&gt; Class (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.aspx&quot;&gt;SoapFormatter&lt;/a&gt; Class (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/5013905936272260269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/5013905936272260269' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5013905936272260269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/5013905936272260269'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/04/what-attribute-should-you-add-to-class.html' title='What attribute should you add to a class to allow it to be serialized?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-7347799402932843303</id><published>2008-03-25T00:47:00.000-07:00</published><updated>2008-03-25T00:53:51.250-07:00</updated><title type='text'>What type of return types can Main have?</title><content type='html'>In C#, Main can return a void type and an int type.  Returning a void type is perhaps the most commonly used return type for main, but returning an integer value from main is also useful when other applications will be running your application, such as being run by a batch file.  The integer value returned from an int main method will be stored in the environment variable %ERRORLEVEL%&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/0fwzzxz2.aspx&quot;&gt;Main() Return Values in C#&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/7347799402932843303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/7347799402932843303' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/7347799402932843303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/7347799402932843303'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/what-type-of-return-types-can-main-have.html' title='What type of return types can Main have?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-8798669299206877159</id><published>2008-03-25T00:15:00.000-07:00</published><updated>2008-03-25T00:38:24.789-07:00</updated><title type='text'>Which access modifiers can be applied to a class in the .NET Framework?</title><content type='html'>The following access modifiers can be applied to classes.  These modifiers determine which classes in the object hierarchy can use the class.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;public&lt;/span&gt; The class can be accessed from any assembly&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;private&lt;/span&gt; The class can only be referenced from within the same class&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;protected&lt;/span&gt; The class can be accessed from the same class or any descendant of the class&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;internal&lt;/span&gt; The class can be accessed from any class within the same assembly&lt;/li&gt;&lt;/ul&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms173121.aspx&quot;&gt;C# Class Access Modifiers&lt;/a&gt; (Microsoft)&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/76453kax.aspx&quot;&gt;VB.NET Access Modifiers&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/8798669299206877159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/8798669299206877159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8798669299206877159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/8798669299206877159'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/which-access-modifiers-can-be-applied.html' title='Which access modifiers can be applied to a class in the .NET Framework?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-3978482202248973178</id><published>2008-03-24T22:38:00.000-07:00</published><updated>2008-05-20T23:41:51.235-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>How can you prevent your class from being inherited by another class in the .NET framework?</title><content type='html'>You can protect your class from being inherited by another class by using the &quot;sealed&quot; modifier on your class.  If any class tries to inherit from your sealed class, they will get an error.  Why would anyone want to seal a class?  Classes are sealed when you would like to prevent static members from being changed.  So if you have a class that define a value for BLACK, you can use sealed to prevent other classes from changing (intentionally or unintentionally) changing BLACK to some other value other than the color of black.&lt;br /&gt;&lt;br /&gt;The code below will not compile and will have have the following error:&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;blockquote&gt;&#39;SealedExample.SealedErrorClass&#39;: cannot derive from sealed type &#39;SealedExample.ExampleClass&#39;&lt;/blockquote&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Sealed Class Example&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;namespace SealedExample&lt;br /&gt;{&lt;br /&gt;    sealed class ExampleClass&lt;br /&gt;    {&lt;br /&gt;        public void MethodToInherit()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&quot;This class is sealed so you can&#39;t inherit this method&quot;);&lt;br /&gt;            Console.WriteLine(&quot;Even though the method is public&quot;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    class SealedErrorClass : ExampleClass&lt;br /&gt;    {&lt;br /&gt;        //This does not work because ExampleClass is sealed&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://www.c-sharpcorner.com/UploadFile/mahesh/SealedClasses11142005063733AM/SealedClasses.aspx&quot;&gt;Using Sealed Classes in .NET&lt;/a&gt; (C# Corner)&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/88c54tsw%28VS.71%29.aspx&quot;&gt;Sealed Keyword&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/3978482202248973178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/3978482202248973178' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3978482202248973178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3978482202248973178'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/how-can-you-prevent-your-class-from.html' title='How can you prevent your class from being inherited by another class in the .NET framework?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-2492240291584410611</id><published>2008-03-22T11:25:00.000-07:00</published><updated>2008-03-22T12:31:49.858-07:00</updated><title type='text'>Which classes can be used to compress streams in the .NET Framework?</title><content type='html'>Stream compression is used to save space and save bandwidth. There are two primary classes used for compression/decompression, the GZipStream and the DeflateStream classes.&lt;br /&gt;&lt;br /&gt;The first thing one might like to know is, which compression class to use?  That depends on how you would like to use the data.  If you will be writing the stream to a file, the GZipStream class includes additional headers that make it suitable for opening with the gzip tool.  The DeflateStream class does not include headers and thus has a slightly smaller size at the expense of being less portable (which may not be a concern if the data never leaves the computer that is running the application)&lt;br /&gt;&lt;br /&gt;Both compresson methods are based on industry standard algorithms that are free of patent protecton.  This allows you to incorporate them into your application with out worrying about intellectual property concerns.&lt;br /&gt;&lt;br /&gt;In later posts we will explore source code for compressing and decompressing streams, but it is important to note the compression size limits. (Which will be repeated each time compression is discussed)&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;GZipStream and DeflateStream classes can&#39;t compress files larger than 4GB&lt;/span&gt;&lt;/blockquote&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx&quot;&gt;System.IO.Compression.GZipStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx&quot;&gt;System.IO.Compression.DeflateStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://blogs.msdn.com/bclteam/archive/2005/06/15/429542.aspx&quot;&gt;Using GZIP for compression in .NET&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/2492240291584410611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/2492240291584410611' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2492240291584410611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2492240291584410611'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/which-classes-can-be-used-to-compress.html' title='Which classes can be used to compress streams in the .NET Framework?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-3337382405632226137</id><published>2008-03-20T16:53:00.000-07:00</published><updated>2008-03-20T17:16:23.955-07:00</updated><title type='text'>Name some classes in the .NET Framework that derive from the Stream Class</title><content type='html'>The following classes all have the Stream class as a base class.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;FileStream&lt;/li&gt;&lt;li&gt;MemoryStream&lt;/li&gt;&lt;li&gt;CryptoStream&lt;/li&gt;&lt;li&gt;NetworkStream&lt;/li&gt;&lt;li&gt;GZipStream&lt;/li&gt;&lt;/ul&gt;By having a common base class, one is guaranteed that a certain set of properties and methods are available.  So in this case, if your code only uses the methods of the stream class, then you can work with data from ANY stream data source.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx&quot;&gt;System.IO.FileStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.memorystream.aspx&quot;&gt;System.IO.MemoryStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.security.cryptography.cryptostream.aspx&quot;&gt;System.Security.Cryptography.CryptoStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx&quot;&gt;System.Net.Sockets.NetworkStream&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx&quot;&gt;System.IO.Compression.GZipStream&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/3337382405632226137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/3337382405632226137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3337382405632226137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3337382405632226137'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/name-some-classes-in-net-framework-that.html' title='Name some classes in the .NET Framework that derive from the Stream Class'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-1701825565148523709</id><published>2008-03-18T21:25:00.000-07:00</published><updated>2008-09-21T16:37:04.698-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>DriveInfo Properties</title><content type='html'>The DriveInfo class class models a drive and allows one to query info about the drives in the system.  While writing the code to exercise this class I was tripped up by a &quot;gotcha&quot;.  Trying to query the volume label of a a CD drive when there is not a CD raises an exception.  To keep the source code simple below, it was decided o check to see if the drive is ready (A CD drive will report not ready if there is there is not a CD)&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;// GetDrives returns an array of all the drives on the system&lt;br /&gt;DriveInfo[] drives = DriveInfo.GetDrives();&lt;br /&gt;&lt;br /&gt;Console.WriteLine(&quot;\n-------------------------------------\n&quot;);&lt;br /&gt;        &lt;br /&gt;//Please keep these two lines if you would like to use this code on your site&lt;br /&gt;Console.WriteLine(&quot;DriveInfo Example&quot;);&lt;br /&gt;Console.WriteLine(&quot;Created by Charles Cozad, http://www.mctscertification.blogspot.com&quot;);&lt;br /&gt;&lt;br /&gt;Console.WriteLine(&quot;\n-------------------------------------\n&quot;);&lt;br /&gt;&lt;br /&gt;foreach (DriveInfo drive in drives)&lt;br /&gt;{&lt;br /&gt;    Console.WriteLine(&quot;Drive Name: {0}&quot;, drive.Name);&lt;br /&gt;    // We check if the drive is ready because calling some of&lt;br /&gt;    // the calls can throw exceptions (such as for a CD drive&lt;br /&gt;    // without a CD in it)&lt;br /&gt;    if (drive.IsReady)&lt;br /&gt;    {&lt;br /&gt;          Console.WriteLine(&quot;Drive Label: {0}&quot;, drive.VolumeLabel);&lt;br /&gt;          Console.WriteLine(&quot;Drive Type: {0}&quot;, drive.DriveType);&lt;br /&gt;          Console.WriteLine(&quot;Drive Formt: {0}&quot;, drive.DriveFormat);&lt;br /&gt;          Console.WriteLine(&quot;Available Free Space: {0}&quot;, drive.AvailableFreeSpace);&lt;br /&gt;          Console.WriteLine(&quot;Total Free Space: {0}&quot;, drive.TotalFreeSpace);&lt;br /&gt;          Console.WriteLine(&quot;Total Space: {0}&quot;, drive.TotalSize);&lt;br /&gt;          Console.WriteLine(&quot;\n+++++++++++++++++++++++++++++\n&quot;);&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;          Console.WriteLine(&quot;Drive info skipped, because the drive is not ready&quot;);&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.driveinfo.aspx&quot;&gt;DriveInfo Class&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/1701825565148523709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/1701825565148523709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1701825565148523709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1701825565148523709'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/driveinfo-properties.html' title='DriveInfo Properties'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-1933002524250264568</id><published>2008-03-18T17:38:00.000-07:00</published><updated>2008-09-21T16:36:07.236-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>FileSystemInfo Properties</title><content type='html'>The FileSystemInfo Class is the base class for the FileInfo and DirectoryInfo classes.  The best way to understand a particular class in the .NET Framework (and any language for that matter) is to write some code to use it.&lt;br /&gt;&lt;br /&gt;Here is a snippet that uses many of the properties available in the FileSystemInfo class.&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;FileSystemInfo exampleFile = new FileInfo(@&quot;C:\WINDOWS\System32\command.com&quot;);&lt;br /&gt;&lt;br /&gt;Console.WriteLine(&quot;\n-------------------------------------\n&quot;);&lt;br /&gt;            &lt;br /&gt;//Please keep these two lines if you would like to use this code on your site&lt;br /&gt;Console.WriteLine(&quot;FileInfo Example&quot;);&lt;br /&gt;Console.WriteLine(&quot;Created by Charles Cozad, http://www.mctscertification.blogspot.com&quot;);&lt;br /&gt;&lt;br /&gt;Console.WriteLine(&quot;\n-------------------------------------\n&quot;);&lt;br /&gt;&lt;br /&gt;if (exampleFile.Exists)&lt;br /&gt;{&lt;br /&gt;      Console.WriteLine(&quot;File Name: {0}&quot;, exampleFile.Name);&lt;br /&gt;      Console.WriteLine(&quot;File Extension: {0}&quot;, exampleFile.Extension);&lt;br /&gt;      Console.WriteLine(&quot;Full File Name: {0}&quot;, exampleFile.FullName);&lt;br /&gt;      Console.WriteLine(&quot;Creation Time: {0}&quot;, exampleFile.CreationTime);&lt;br /&gt;      Console.WriteLine(&quot;Last Access Time: {0}&quot;, exampleFile.LastAccessTime);&lt;br /&gt;      Console.WriteLine(&quot;Last Write Time: {0}&quot;, exampleFile.LastWriteTime);&lt;br /&gt;      Console.WriteLine(&quot;File Attributes: {0}&quot;, exampleFile.Attributes);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;      Console.WriteLine(&quot;File does not exist&quot;);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.io.filesysteminfo.aspx&quot;&gt;FileSystemInfo Class&lt;/a&gt; (Microsoft)&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/1933002524250264568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/1933002524250264568' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1933002524250264568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/1933002524250264568'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/filesysteminfo-properties.html' title='FileSystemInfo Properties'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-6722153669042045240</id><published>2008-03-08T18:12:00.000-08:00</published><updated>2008-03-08T18:40:38.228-08:00</updated><title type='text'>Using constraints with generics</title><content type='html'>Generics are less useful if you must write code that works with ALL objects because you would be limited to to the capabilities of the base Object class.  Constraints allow you to limit the types of objects the caller can use.  This additional information allows you (and the compiler) to make greater assumptions about which capabilities are available.&lt;br /&gt;&lt;br /&gt;Generics can be constrained in the following ways&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Interface&lt;/span&gt; - Allow only types that implement the specified interface&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Base Class&lt;/span&gt; - Allow only types that are descendents of (or are) the specified base class&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Constructor&lt;/span&gt; - Allow only types that have a parameterless constructor&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Reference or value type&lt;/span&gt; - Allows value or reference types&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/d5x73970%28VS.80%29.aspx&quot;&gt;Constraints on Type Parameters, C# (Microsoft)&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms379608.aspx&quot;&gt;Defining and Using Generics, Visual Basic (Microsoft)&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/6722153669042045240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/6722153669042045240' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/6722153669042045240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/6722153669042045240'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/using-constraints-with-generics.html' title='Using constraints with generics'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-2617946993104169910</id><published>2008-03-08T16:25:00.000-08:00</published><updated>2008-05-20T23:46:33.726-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><title type='text'>Range of built-in value types</title><content type='html'>The code snippet below will display the minimum and maximum values of the built in value types in the .NET Framework.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c-sharp:nogutter&quot;&gt;&lt;br /&gt;Console.WriteLine(&quot;Built-in value type ranges&quot;);&lt;br /&gt;&lt;br /&gt;Console.WriteLine(&quot;SByte Min: &quot; + System.SByte.MinValue + &quot; Max: &quot; + System.SByte.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Byte Min: &quot; + System.Byte.MinValue + &quot; Max: &quot; + System.Byte.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Int16 Min: &quot; + System.Int16.MinValue + &quot; Max: &quot; + System.Int16.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Int32 Min: &quot; + System.Int32.MinValue + &quot; Max: &quot; + System.Int32.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Int64 Min: &quot; + System.Int64.MinValue + &quot; Max: &quot; + System.Int64.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Single Min: &quot; + System.Single.MinValue + &quot; Max: &quot; + System.Single.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Double Min: &quot; + System.Double.MinValue + &quot; Max: &quot; + System.Double.MaxValue);&lt;br /&gt;Console.WriteLine(&quot;Decimal Min: &quot; + System.Decimal.MinValue + &quot; Max: &quot; + System.Decimal.MaxValue);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After you run the application you get the following output:&lt;br /&gt;&lt;pre&gt;Built-in value type ranges&lt;br /&gt;SByte Min: -128 Max: 127&lt;br /&gt;Byte Min: 0 Max: 255&lt;br /&gt;Int16 Min: -32768 Max: 32767&lt;br /&gt;Int32 Min: -2147483648 Max: 2147483647&lt;br /&gt;Int64 Min: -9223372036854775808 Max: 9223372036854775807&lt;br /&gt;Single Min: -3.402823E+38 Max: 3.402823E+38&lt;br /&gt;Double Min: -1.79769313486232E+308 Max: 1.79769313486232E+308&lt;br /&gt;Decimal Min: -79228162514264337593543950335 Max: 79228162514264337593543950335&lt;/pre&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://www.spunkysoftware.com/download/TypeRanges/Program.cs&quot;&gt;TypeRanges Source&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/2617946993104169910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/2617946993104169910' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2617946993104169910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2617946993104169910'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/range-of-built-in-value-types.html' title='Range of built-in value types'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-4243629762152643770</id><published>2008-03-08T10:22:00.001-08:00</published><updated>2008-03-08T11:00:16.167-08:00</updated><title type='text'>Name some commonly used interfaces in .NET</title><content type='html'>Interfaces act as a &quot;contract&quot; in the .NET Framework.  The contract is that all classes implementing the interface will have a common set of members.&lt;br /&gt;&lt;br /&gt;Of the many interfaces built into the .NET Framework, the interfaces listed below are commonly used and worth committing to memory.&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.icomparable%28VS.80%29.aspx&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.icomparable%28VS.80%29.aspx&quot;&gt;IComparable&lt;/a&gt; (Implemented by types with values that can be ordered, this interface is required for sorting)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.idisposable%28VS.80%29.aspx&quot;&gt;IDisposable&lt;/a&gt; (Allows for an object to be manually disposed, important for objects that consume limited or valuable resources)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;IConvertible&quot;&gt;IConvertible&lt;/a&gt; (Allows a class to be converted to a base type, such as int or string)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;IConvertible&quot;&gt;IClonable&lt;/a&gt; (Allows the implementing object to be copied)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms131187%28VS.80%29.aspx&quot;&gt;IEquatable&lt;/a&gt; (Allows for two instances of a class to be compared using the == operator)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.iformattable%28VS.80%29.aspx&quot;&gt;IFormattable&lt;/a&gt; (Allows for more control over formatting than the ToString method)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/87d83y5b.aspx&quot;&gt;Interfaces in C# (Microsoft)&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/h9xt0sdd.aspx&quot;&gt;Interfaces in VB (Microsoft)&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/4243629762152643770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/4243629762152643770' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/4243629762152643770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/4243629762152643770'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/name-some-commonly-used-interfaces-in.html' title='Name some commonly used interfaces in .NET'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-51450287960117362</id><published>2008-03-06T23:21:00.000-08:00</published><updated>2008-03-07T00:16:34.067-08:00</updated><title type='text'>Tips for avoiding unnecessary boxing and unboxing</title><content type='html'>Boxing and unboxing can add overhead to runtime operations.  You should especially try to avoid boxing and unboxing when you are performing compute intensive, repetitive tasks.  Observing the following three tips will help eliminate unnecessary boxing and unboxing.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Implement type specific, overloaded versions of functions. So if a function is often called with a particular type of argument, then create specific version of the function that accepts that type of parameter. (Instead of just creating one version that selects an Object argument)&lt;/li&gt;&lt;li&gt;Use generics when ever possible instead of accepting Object arguments.&lt;/li&gt;&lt;li&gt;Override the ToString, Equals, and GetHash virtual members when defining structures.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://blog.cumps.be/boxing-unboxing-in-net/&quot;&gt;Boxing and Unboxing (David Cumps)&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/51450287960117362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/51450287960117362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/51450287960117362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/51450287960117362'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/tips-for-avoiding-unnecessary-boxing.html' title='Tips for avoiding unnecessary boxing and unboxing'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-2795186753516217146</id><published>2008-03-06T21:59:00.000-08:00</published><updated>2008-03-19T00:29:30.930-07:00</updated><title type='text'>What is boxing and unboxing?</title><content type='html'>Boxing converts a value to a reference type, and unboxing converts a reference type to a value type.&lt;br /&gt;&lt;br /&gt;The .NET code samples below show boxing and unboxing.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Boxing Example&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;vb.net:nogutter&quot;&gt;&lt;br /&gt;&#39; VB&lt;br /&gt;Dim i As Integer = 123&lt;br /&gt;Dim o As Object = CType(i, Object)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c#:nogutter&quot;&gt;&lt;br /&gt;// C#&lt;br /&gt;int i = 123;&lt;br /&gt;object o = (object)  i;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Unboxing Example&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;vb.net:nogutter&quot;&gt;&lt;br /&gt;&#39; VB&lt;br /&gt;Dim o As Object = 123&lt;br /&gt;Dim i As Integer = CType(o, Integer)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;c#:nogutter&quot;&gt;&lt;br /&gt;// C#&lt;br /&gt;object o = 123;&lt;br /&gt;int i = (int)  o;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://aspalliance.com/986_Boxing_and_Unboxing_in_NET.all&quot;&gt;Boxing and Unboxing (ASP Alliance)&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/2795186753516217146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/2795186753516217146' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2795186753516217146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/2795186753516217146'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/what-is-boxing-and-unboxing.html' title='What is boxing and unboxing?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2230386454320727695.post-3455731600259051077</id><published>2008-03-06T18:00:00.000-08:00</published><updated>2008-03-06T18:25:25.224-08:00</updated><title type='text'>What order should exceptions be caught in, least specific to most specific or vice versa?</title><content type='html'>Exceptions within the .NET frame work should be caught from &lt;span style=&quot;font-weight: bold;&quot;&gt;most specific&lt;/span&gt; to &lt;span style=&quot;font-weight: bold;&quot;&gt;least specific&lt;/span&gt;. This is because only the first catch block with a matching exception type is the only block that is executed.  So in other words if you catch  a more general exception before a less general exception, the code will never make it beyond the general exception that is caught.  The more specific catch block becomes &lt;a href=&quot;http://en.wikipedia.org/wiki/Unreachable_code&quot;&gt;unreachable code&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Additional Resources&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms229005.aspx&quot;&gt;.NET Exception Handling (Microsoft)&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;&lt;br /&gt;
----- Advertisement ---------
&lt;br /&gt;
&lt;a href=&quot;http://click.linksynergy.com/fs-bin/click?id=4km3R7ZgMhc&amp;offerid=131313.10000033&amp;type=3&amp;subid=0&quot; &gt;Know&amp;nbsp;where&amp;nbsp;your&amp;nbsp;Money&amp;nbsp;goes.&amp;nbsp;Download&amp;nbsp;Microsoft&amp;nbsp;Money&amp;nbsp;today.&lt;/a&gt;&lt;IMG border=0 width=1 height=1 src=&quot;http://ad.linksynergy.com/fs-bin/show?id=4km3R7ZgMhc&amp;bids=131313.10000033&amp;type=3&amp;subid=0&quot; /&gt;
&lt;br /&gt;
----------------------------------------
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mctscertification.blogspot.com/feeds/3455731600259051077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2230386454320727695/3455731600259051077' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3455731600259051077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2230386454320727695/posts/default/3455731600259051077'/><link rel='alternate' type='text/html' href='http://mctscertification.blogspot.com/2008/03/what-order-should-exceptions-be-caught.html' title='What order should exceptions be caught in, least specific to most specific or vice versa?'/><author><name>wizkid</name><uri>http://www.blogger.com/profile/16634909673656268057</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://farm1.static.flickr.com/206/443227240_fafb19e47e.jpg?v=0'/></author><thr:total>0</thr:total></entry></feed>