- C# 2.0
- Class Designer
- Unit Testing
- Code Coverage
- FXCop Integration
- Debugging: DataTips, Visualizers and Viewers
- Refactoring
- Improved IntelliSense
- Code Snippets
- Profiles
- Strongly-typed resource class generator
- Improved (not perfect) Windows Forms controls
Microsoft has released a free LibCheck tool that allows you to compare two versions of an assembly, and determine the differences. The tool reports the differences as a combination of 'removed' and 'added' APIs. The tool is limited to looking only at APIs (i.e, it can't check for behavioral changes), and only compares public differences, or changes which are deemed to be 'breaking'. The tool can be used to quickly determine what has changed between one version of your assembly and another, and can help ensure that you won't introduce any breaking changes to clients of your assembly. Instructions and intended use of the tool are described in the 'libcheck tool specification' document with the zip file.
This was a feature I always was missing. VB6 had this, VS.NET didn't. Thanks MS.
For a long time I thought that I only had to set the Cursor.Current to a WaitCursor before a long running operation, the .NET runtime would reset it back to the Default cursor. Turns out that this is only true when the mouse is moved. Bummer.
Cursor.Current = Cursors.WaitCursor;
The solution for this problem is very easy. I created a helper class called WaitCursor which set the Cursor.Current and restores it to the original value when it it disposed.
public
sealed
class WaitCursor : IDisposable {        
 private Cursor _prev;
 public WaitCursor(){
   _prev= Cursor.Current;
   Cursor.Current = Cursors.WaitCursor;
 }
 publicvoid Dispose(){
   Cursor.Current =_prev;
 }
}
I create the instance of the WairCursor class inside a using statement. This will automatically call the Dispose() method when it goes out of scope.
There is a difference in disposing Modal and Non-Modal forms. In a training I gave last week I noticed that even experienced developers didn't know that Modal Dialogs don't dispose automatically, Non-Modal do.
private
void
buttonShowNonModalForm
(
object
sender
, System.EventArgs e){
 new TestForm().Show();
}
privatevoidbuttonShowModalDialog(objectsender, System.EventArgs e){
 new Form2().ShowDialog();
}
The solution to this problem is very simple by creating the Form instance within a using block. This will dispose the Form when it is closed.
private
void
buttonShowModalDialog
(
object
sender
, System.EventArgs e){
 using(TestForm f =new TestForm()){
   f.ShowDialog();
 }
}
An alternative solution uses a try/finnaly. Personally I prefer the previous, it is easier to read and write.
The C# code editor in Visual Studio.NET 2003 does not handle whitespaces automatically like the VB.NET code editor does. This Add-In solves this problem by adding the 'Handle WhiteSpace' menu option to the Visual Studio.NET 2003 Tools menu. This option formats the C# code of the active code editor. This includes:
-
Space before: method declaration parentheses, method call parentheses, statement parentheses, braces and brackets
-
Space after: comma and semicolon
-
Space around: operators
-
Double space
I have found a solution for a problem which I had for a long time. I was unable to set the ToolboxBitmap attribute for a component using the (type, string) constructor. I found the solution for this problem (using an internal ResFinder class) on www.bobpowell.net. This site has also some other Windows Forms Tips and Tricks. Great!
I'm testing Visual C# 2005 Express Edition Beta and I really like it. It has all of the features which I need to build Windows Forms applications. The Editor has also all new IntelliSense, Refactoring and Code Snippets features. They work great and really can boost productivity.
I have tested it on a PC with only 256Mb of ram. This is for the beta not enough. You need at least 512Mb.
I'm using the Online MSDN Help, it works OK. The looks are good but I find it difficult to get to the 'overview' of a class.
For professional development I would advise to use Visual Studio. For hobby work use the Express versions.
It took me today some time to figure out how to sort an array of strings case-sensitively. The default behavior of the Array.Sort() uses an default Comparer object which should be case-sensitive. When I tested this I found out that I had misinterpreted the definition of 'case-sensitive'. What I wanted was 'Oridinal' sorting. So I created an OrdinalStringComparer class which implements IComparer and I got what I wanted.
using System;
using System.Collections;
namespace ReflectionIT.Test {
 class Class1{
   [STAThread]
   staticvoid Main(string[]args){
     Test(new CaseInsensitiveComparer());
     Test(Comparer.Default);    
     Test(new OridinalStringComparer());
   
     Console.ReadLine();
   }
   privatestaticvoid Test(IComparer comparer){
     string[]words=newstring[]{"c","a","A","aB","ab","Ab"};
     Array.Sort(words,comparer);
   
     Console.WriteLine(comparer.GetType().Name +":");
     foreach(stringwordinwords){
       Console.WriteLine(word);
     }
     Console.WriteLine();
   }
   
 }
   
 publicclass OridinalStringComparer : IComparer {
   
   int IComparer.Compare(object x,object y ){
     returnstring.CompareOrdinal((string)x,(string)y);
   }
   
 }
   
}
And when you run this program you get the following output:
CaseInsensitiveComparer:
A
a
Ab
ab
aB
c
Comparer:
a
A
ab
aB
Ab
c
OridinalStringComparer:
A
Ab
a
aB
ab
c
This table gives you an overview of all collections in the System.Collections and System.Collections.Specialized namespaces.
Class |
Key |
Value |
Remarks |
System.Array |
|
? |
Predefined size, used for passing data around. |
ArrayList |
|
Object |
Easy to work with, provides basic collection functionality and can easily be
converted to an Array. |
BitArray |
|
Boolean |
Manages a compact array of bit values, which are represented
as Booleans
|
CollectionBase |
|
? |
Abstract base for building your own collection classes. |
DictionaryBase |
Object |
? |
Abstract base for building your own collection classes using a key-value pair. |
HashTable |
Object |
Object |
Provides high performance access to items in the key-value pair collection, by
a specific key. |
Queue |
|
Object |
Implements the FIFO mechanism. |
ReadOnlyCollectionBase |
|
Object |
Abstract base for building your own read-only collection classes. |
SortedList |
Object (sorted) |
Object |
Provides access to items in the collection by a specific key or an index
(GetByIndex(int)). |
Stack |
|
Object |
Implements the LIFO mechanism. |
Specialized.HybridDictionary
|
Object |
Object |
Uses internally a ListDictionary class when the collection is small, and
switches automatically to a Hashtable class when the collection gets large. |
Specialized.ListDictionary |
Object |
Object |
Is designed to be used for collections with 10 or less items, while the
Hashtable is designed to contain more items. |
Specialized.NameObjectCollectionBase |
String |
? |
Abstract base for building your own collection classes using a key-value pair. |
Specialized.NameValueCollection |
String (sorted) |
String |
NameValueCollection class is the strong type equivalent of the SortedList
class, for the String class. |
Specialized.StringCollection |
|
Object |
Strongly typed ArrayList for the String class. |
Specialized.StringDictionary |
String |
String |
Strongly typed Hashtable for the String class, not sorted. |
Read also Jan Tielens article on the MSDN Belux website.