Category Archives: Study

C# var keyword

I’m working my way through the C# 3.0 Language Enhancements videos on LearnVisualStudio.Net.  (Note:  LearnVisualStudio has many videos that are available for free from the MSDN website, but I think that you need a paid subscription to view this series.)  When I’m studying new programming concepts, I find that hearing someone talk about it helps me […]

C# “as” and “is” keywords

“Is” is exactly what I have been looking for.  You use it to check the type of an object.  For example: if(a is long) Gabe Wishnie points out that “is” is much more efficient than: if( a.GetType() == typeof(long)) “As” is a method of performing a typecast that gives you a null pointer rather than […]

.Net BackgroundWorker class

The BackgroundWorker class is an easy way to start up a thread from the GUI to run some lengthy action in the background.  Key points are: The DoWork event runs on the background thread.  You can’t interact with the GUI from there.  The ProgessChanged and RunWorkerCompleted events are raised by the background thread into the […]

Using regular expressions to find the text between two delimiters

I have a string like this:  “This is a [abcd] string”.  I want to find the text between the square brackets.  Looks like a job for regular expressions! This regular expression works:  “\[.*\]“.  Very straightforward (for a regular expression) – I like it! Then I saw this regular expression in some question and answer forum:  […]

Getting a list of SQL Server databases on the network

I found this pretty easily with an Internet search.  Copying it here so I can be sure to find it next time I want it.  Courtesy of Dan Dittenhafer private static List EnumSqlServers() { System.Data.DataTable sqlInstances = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources(); List listSqlServers = new List();// Loop to load the unique server names foreach (System.Data.DataColumn col in sqlInstances.Columns) […]

Adding icons to Windows Forms

I added an icon to a Windows Form, but it didn’t display.  Why not?  Because even though Visual Studio by default creates a 32x32x16 icon, you really need a 32x32x256 icon.  Right-click on the icon editor screen to select the desired format.  Thanks Jason Black.  

Taking a look at the ASP.Net Personal Web Site Starter Kit

It occurred to me that I could learn a lot by studying the techniques used in the Personal Web Site Starter Kit that comes with ASP.Net.  I laughed when I read this line in the Welcome page.  The italics are mine. You can use the site as-is with some small customizations, such as adding your own […]

Useful Transact-SQL commands


Raising an event in C#

Raising an event in C# is ridiculously complicated, but here goes.  This is based on MSDN “How to:  Implement Events in Your Class”. ITEM 1 Create a class for the event arguments. public class FactoryInfoEventArgs : EventArgs { private string mSource; public string Source { get { return mSource; } set { mSource = value; […]

Reading/Writing XML files

1.  XmlWriter – This is simple but tedious and error prone.  You can create an XmlWriter and use WriteStartElement, WriteElementString, and WriteEndElement to explictly write the XML statements. If writing to a file, set the XmlWriterSettings.Indent property to true.  Otherwise you don’t get any indents or carriage returns in the output file. XmlWriterSettings settings = new […]