Blog - Title

  • The C# Team

    Leverage the C# Preprocessor

    • 7 Comments
    Like other languages in the C-family, C# supports a set of 'preprocessor' directives , most notably #define , #if and #endif (technically, csc.exe does not literally have a preprocessor as these symbols are resolved at the lexical analysis phase, but...
  • The C# Team

    Avoiding Type Name-Clashes using 'using'

    • 10 Comments
    You are already aware that the C# using keyword allows you to supply hints to the compiler regarding the fully qualified name of the types within a given *.cs file. However, what you may not know is that the using keyword also allows you to build aliases...
  • The C# Team

    Build 'Consistent' .NET assemblies with FxCop

    • 1 Comments
    The term 'best practices' sends chills up the spines of many people. Reason being, what is 'best' for one is 'horrible' for another. However, if you are interested in ensuring that your custom .NET assemblies are in-sync with the coding guidelines proposed...
  • The C# Team

    Simplified Interface Implementation a la VS .NET 2003

    • 2 Comments
    Another helpful feature of VS .NET 2003 has to do with the implementation of interface types. As you know, when a class or structure agrees to implement a given interface, it must implement all of the members. Assume you wish to support an interface containing...
  • The C# Team

    Simplified Event Handling a la VS .NET 2003

    • 3 Comments
    Working with events under the .NET platform requires you to be aware of a number of details. For example, if you know the name of the event you wish to handle, you must then know the name of the related delegate type. Once you know that much, you must...
  • The C# Team

    Integrate ildasm.exe into VS .NET 2002

    • 1 Comments
    VS .NET allows you to add any number of external tools to the Tools menu. One very helpful technique is to configure ildasm.exe to automatically load up the current assembly being compiled. While VS .NET 2003 sets this up automatically, VS .NET 2002 may...
  • The C# Team

    Add Custom .NET Assemblies to the Add Reference Dialog

    • 15 Comments
    As you most likely know by now, the Add References dialog of Visual Studio .NET does not list each and every assembly on your machine, does not directly map to the Global Assembly Cache and does not list your custom assemblies. Typically this limitation...
  • The C# Team

    Leverage C# Response Files at the Command Line

    • 3 Comments
    Although I'd bet most of you make use of VS .NET as opposed to the raw command line complier, csc.exe can be quite useful in a number of circumstances. However, few of us enjoy typing lengthy command line flags such as: csc /r: MyAsm.dll;MyOtherAsm...
  • The C# Team

    Be Aware of wincv.exe

    • 7 Comments
    When you install the .NET SDK / VS.NET, you are provided with numerous stand alone programming tools, one of which is named wincv.exe ( Windows Class Viewer ). Many developers are unaware of wincv.exe, as it is buried away under the C:\Program Files\Microsoft...
  • The C# Team

    Utilize the Server Explorer

    • 0 Comments
    Visual Studio .NET provides a very interesting view of the world named the Server Explorer (which can be activated from the View menu). While you may already be aware many of these items can be opened within VS .NET for editing (for example, opening a...
  • The C# Team

    Obtain Type Information on the Fly using typeof

    • 2 Comments
    All .NET assemblies contain vivid type information which describes the structure of every internal and external type (this can be verified by loading an assembly into ildasm.exe and clicking the ctrl-m keystroke). On a related note, many methods in the...
  • The C# Team

    Interacting with overloaded operators from overloaded operator challenged languages

    • 3 Comments
    Like the C++ language, C# allows you to overload operators for your custom types. For example, assume you have a structure named MyPoint which has overloaded the plus operator. If this is the case, you can 'add' two MyPoints as so: // Add two MyPoint...
  • The C# Team

    How to keep a local variable in scope across a try and catch block?

    • 19 Comments
    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...
  • The C# Team

    Does C# support variable arguments (vararg's) on methods?

    • 4 Comments
    There was a suggestion/question on the Product Feedback site for VS2005 that suggested that the params keyword may not be that well understood. The params keyword can be applied on a method parameter that is an array. When the method is invoked, the...
  • The C# Team

    What is the equivalent to regsvr32 in .NET?

    • 12 Comments
    Where you once used Regsvr32 on unmanaged COM libraries, you will now use Regasm on managed .NET libraries. “ Regsvr32 is the command-line tool that registers .dll files as command components in the registry“ “Regasm.exe, the...
  • The C# Team

    Are Generics in .NET like Templates in C++?

    • 9 Comments
    No. While Generic types do have a similar syntax to C++ templates, they are instantiated at runtime as opposed to compile time, and they can be reflected on via meta-data. Also, in Generics, member access on the type paramater is verified based on...
  • The C# Team

    Why does my switch statement works differently?

    • 5 Comments
    C# does not support an explicit fall through for case blocks (unless the block is empty) For an explanation of why, see Why is the C# switch statement designed to not allow fall through, but still require a break? on MSDN The following code is not...
  • The C# Team

    Why does C#'s iterators feature spit out a class definition instead of a struct definition?

    • 1 Comments
    Q: Why does C#'s iterators feature spit out a class definition instead of a struct definition? The iterators feature in C# generates classes that implement the enumerators required. This is detailed in the C# Specification . Why doesn't it use structs...
  • The C# Team

    How can I run another application or batch file from my Visual C# .NET code?

    • 34 Comments
    Posted by: Duncan Mackenzie , MSDN This post applies to Visual C# .NET 2002/2003 Suppose you want to run a command line application, open up another Windows program, or even bring up the default web browser or email program... how can you do this from...
  • The C# Team

    How do I cast a string to an int, float, double, etc?

    • 19 Comments
    You can use the Convert class or the Parse method of the built-in type you are casting to. i.e. string myStr = "123"; int myParsedInt = Int32.Parse(myStr); int myConvertedInt = Convert.ToInt32(myStr); This example uses the int type, but you can also...
  • The C# Team

    How are return values from a delegate handled?

    • 5 Comments
    Q: How are multiple return values from a delegate handled? In C#, it's possible to write a delegate such as: delegate double GetResult(params double p); If there is more than one method on this delegate, there are multiple return values. A...
  • The C# Team

    Why don't nullable relational operators return bool? instead of bool?

    • 12 Comments
    Q: Why don't nullable relational operators return “bool?” instead of “bool“? Nullable types are a new feature of C# 2.0 . When dealing with nullable types, if you write the following: int? i = 15; int? j = 16; the type...
  • The C# Team

    Why can't I use the same variable as an inner loop does?

    • 12 Comments
    Q: Why can't I do the following: namespace Bug { class Class1 { [ STAThread ] static void Main ( string [] args ) { for ( int i = 0; i < 100; i ++ ) { } int i = 0; } } } the compiler gives me an error...
  • The C# Team

    How do I write a method that accepts a variable number of parameters?

    • 11 Comments
    Update: Named and optional (default) parameters are available starting from C# 4.0. For more information, see Named and Optional Arguments (C# Programming Guide) . Q: How do I write a method that accepts a variable number of parameters? ...
  • The C# Team

    Why doesn't C# support static method variables?

    • 24 Comments
    Q: In C++, it's possible to write a static method variable, and have a variable that can only be accessed from inside the method. C# doesn't provide this feature. Why? A: There are two reasons C# doesn't have this feature. First, it is possible...
Page 4 of 6 (142 items) «23456