Browse by Tags

How to keep a local variable in scope across a try and catch block?
12 August 04 06:33 PM
The following code won't work, because conn goes out of scope before you enter the catch block. try { Connection conn = new Connection(); conn.Open(); } catch { if (conn != null ) conn.Close(); } The fix is simple - just declare conn before entering the Read More...
Where can I get a full comparison between C# and VB.NET?
12 March 04 02:31 AM
Microsoft provides a very full language equivalents page which compares not only C# and VB.NET, but also other languages targeted at the .NET framework. It looks at the equivalent concepts, keywords, types, operators etc. A very valuable resource when Read More...
Postedby CSharpFAQ | 6 Comments    
Is there an equivalent of MyClass?
12 March 04 02:30 AM
No, C# doesn't have an equivalent of VB.NET's MyClass keyword. If you want to guarantee not to call an overridden version of a method, you need to make it non-virtual in the first place. [Author: Jon Skeet] Read More...
Postedby CSharpFAQ | 8 Comments    
What do I use instead of addressof?
12 March 04 02:29 AM
To create delegate instances in C#, you just specify the delegate type, the method, and (if you want to create a delegate targetting a different instance or type from the current one) the target. For instance, each of these creates a ThreadStart delegate: Read More...
Postedby CSharpFAQ | 1 Comments    
How do I get the rightmost part of a string, as with the VB Right function?
12 March 04 02:28 AM
Use String.Substring . Assuming that x is a string of length at least n , to get the last n characters, you would use x.Substring(x.Length-n) . Note that the above assumes that the string is at least n characters long. For a more robust version, you might Read More...
Postedby CSharpFAQ | 10 Comments    
What are the equivalents of Me and MyBase?
12 March 04 02:27 AM
Me in C# is this , and MyBase in C# is base . To access normal members, just use this.memberName or base.memberName . For information about chaining constructors together, see my article on constructors . [Author: Jon Skeet] Read More...
Postedby CSharpFAQ | 0 Comments    
What's the equivalent of Nothing?
12 March 04 02:26 AM
For reference types, the equivalent of VB's Nothing is C#'s null . For value types, it's the default value - 0 , false , etc. [Author: Jon Skeet] Read More...
Postedby CSharpFAQ | 4 Comments    
Why doesn't C# have VB.NET's 'with' operator?
11 March 04 02:02 AM
Many people, including the C# language designers, believe that 'with' often harms readability, and is more of a curse than a blessing. It is clearer to declare a local variable with a meaningful name, and use that variable to perform multiple operations Read More...
What are the advantages of C# over VB.NET and vice versa?
11 March 04 01:59 AM
The choice between C# and VB.NET is largely one of subjective preference. Some people like C#'s terse syntax, others like VB.NET's natural language, case-insensitive approach. Both have access to the same framework libraries. Both will perform largely Read More...

This Blog

Syndication

Page view tracker