<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C# Frequently Asked Questions : Tips</title><link>http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx</link><description>Tags: Tips</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How do I create a constant that is an array?</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/12/03/274417.aspx</link><pubDate>Fri, 03 Dec 2004 20:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:274417</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/274417.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=274417</wfw:commentRss><description>&lt;p&gt;
Strictly speaking you can't, since const can only be applied to a field or local whose value is known at compile time.
&lt;/p&gt;&lt;p&gt;
In both the lines below, the right-hand is not a constant expression (not in C#).
&lt;/p&gt;
&lt;pre
&gt;const int [] constIntArray = newint [] {2, 3, 4};
 // error CS0133: The expression being assigned to 'constIntArray' must be constant
const int [] constIntArrayAnother = {2, 3, 4};
 // error CS0623: Array initializers can only be used in a variable or field
 //               initializer. Try using a new expression instead. 
&lt;/pre&gt;
&lt;p&gt;
However, there are some workarounds, depending on what it is you want to achieve.
&lt;/p&gt;&lt;p&gt;
If want a proper .NET array (System.Array) that cannot be reassigned, then static readonly will do for you. 
&lt;/p&gt;
&lt;pre&gt;
static readonly int [] constIntArray = new int[] {1, 2, 3};
&lt;/pre&gt;
&lt;/p&gt;
The constIntArray field will be initialized before it its first use.
&lt;/p&gt;&lt;p&gt;
If, on the other hand, you really need a const set of values (say as an argument to an attribute constructor), then - if you can limit yourself to integral types - an enum would serve you well.
&lt;/p&gt;&lt;p&gt;
For example:
&lt;/p&gt;
&lt;pre&gt;
[Flags]
public enum Role
{
	Administrator = 1,
	BackupOperator = 2,
	// etc. 
}

public class RoleAttribute : Attribute
{
	public RoleAttribute()
	{
		CreateRole = DefaultRole;
	}

	public RoleAttribute(Role role)
	{
		CreateRole = role;
	}

	public Role CreateRole
	{
		get { return this.createRole; }
		set { this.createRole = value; }
	}

	private Role createRole = 0;
	public const Role DefaultRole = Role.Administrator
	 | Role.BackupOperator;
}

[RoleAttribute(RoleAttribute.DefaultRole)]
public class DatabaseAccount
{
	//.............. 
}
&lt;/pre&gt;
&lt;p&gt;
RoleAttribute, instead of taking an array, would only take a single argument of flags (appropriately or-ed). If the underlying type of the Role enum is long or ulong, that gives you 64 different Roles.
&lt;/p&gt;&lt;p&gt;
[Author: SantoshZ]
&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=274417" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/C_2300_+Language+and+Compiler/default.aspx">C# Language and Compiler</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/General/default.aspx">General</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>How do I get and set Environment variables?</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/12/02/273785.aspx</link><pubDate>Thu, 02 Dec 2004 17:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:273785</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/273785.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=273785</wfw:commentRss><description>&lt;p align="left"&gt;&lt;span id="qd_lblAnswer" style="FONT-SIZE: x-small"&gt;&lt;font face="Arial" size="3"&gt;Use the &lt;b&gt;System.Environment&lt;/b&gt; class.&lt;br /&gt;Specifically the &lt;b&gt;GetEnvironmentVariable&lt;/b&gt; and &lt;b&gt;SetEnvironmentVariable&lt;/b&gt; methods.&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;font face="Arial"&gt;Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to &lt;em&gt;set &lt;/em&gt;environment variables is new to the Whidbey release, as is the &lt;b&gt;EnvironmentVariableTarget&lt;/b&gt; enumeration which lets you separately specify process, machine, and user. &lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font face="Arial"&gt;Brad Abrams blogged on &lt;a href="http://weblogs.asp.net/brada/archive/2004/01/03/50984.aspx"&gt;this&lt;/a&gt; way back at the start of this year, and followed up with a&amp;nbsp;&lt;a href="http://weblogs.asp.net/brada/archive/2004/02/23/78870.aspx"&gt;solution &lt;/a&gt;for pre-Whidbey users.&lt;/font&gt;&lt;/p&gt; &lt;p align="left"&gt;&lt;font face="Arial"&gt;[Author: SantoshZ]&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=273785" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/General/default.aspx">General</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/.NET+Framework/default.aspx">.NET Framework</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Preprocess Win32 Messages through Windows Forms</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245412.aspx</link><pubDate>Wed, 20 Oct 2004 23:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245412</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245412.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245412</wfw:commentRss><description>&lt;p&gt;In the unmanaged world, it was quite common to intercept Win32 messages as they were plucked off the message queue.  In that rare case in which you wish to do so from a managed Windows Forms application, your first step is to build a helper class which implements the IMessageFilter interface.  The sole method, PreFilterMessage(), allows you to get at the underlying message ID, as well as the raw WPARAM and LPARAM data.  By way of a simple example:&lt;/p&gt;

&lt;pre&gt;public class MyMessageFilter : IMessageFilter 
{
  public bool PreFilterMessage(ref Message m) 
  {
    // Intercept the left mouse button down message.
    if (m.Msg == 513) 
    {
      MessageBox.Show("WM_LBUTTONDOWN is: " + m.Msg);
      return true;
    }
    return false;
  }
}&lt;/pre&gt;

&lt;p&gt;At this point you must register your helper class with the Application type:&lt;/p&gt;

&lt;pre&gt;public class mainForm : System.Windows.Forms.Form
{
  private MyMessageFilter msgFliter = new MyMessageFilter();

  public mainForm()
  {
    // Register message filter.
    Application.AddMessageFilter(msgFliter);		
  }
&amp;#8230;
}&lt;/pre&gt;

&lt;p&gt;At this point, your custom filter will be automatically consulted before the message makes its way to the registered event hander. Removing the filter can be accomplished using the (aptly named) static Application.RemoveMessageFilter() method.&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245412" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Be Mindful of the References / 'using' / Manifest Relationship</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245411.aspx</link><pubDate>Wed, 20 Oct 2004 23:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245411</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245411.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245411</wfw:commentRss><description>&lt;p&gt;Given that the .NET platform encourages binary reuse of types, it is commonplace to set references to external assemblies using the Visual Studio .NET Add Reference dialog box.  Many programmers (especially those of the C(++) ilk) fear that adding unnecessary external references can result in a bit of 'code bloat'.  Nothing could be further from the truth.  When you add assembly references or make use of the 'using' keyword, csc.exe will ignore any assembly which you have not actually made use of in your code. Thus, if you were to set a reference to System.Data.dll and System.Windows.Forms.dll but only authored the following code:&lt;/p&gt;

&lt;pre&gt;using System;
using System.Data;  // Ignored. 
using System.Windows.Forms; // Ignored. 

public class MyClass
{
  public static void Main()
  {
    Console.WriteLine("Hi there.");
  }
}&lt;/pre&gt;

&lt;p&gt;the compiler would only reference the mandatory mscorlib.dll.  &lt;/p&gt;

&lt;p&gt;As you may be aware, when you open up a .NET assembly using ildasm.exe, the MANIFEST icon may be double clicked to open a window describing the binary under investigation.  At the very top, you will see a list of each external assembly the current assembly was compiled against (provided that it was actually used):&lt;/p&gt;

&lt;pre&gt;.assembly extern mscorlib
{ &amp;#8230; }&lt;/pre&gt;

&lt;p&gt;Bottom line?  Don't waist your time stripping out unused 'using' statements or assembly references from your application.  The C# compiler will do so for you automatically. &lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003/2005&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245411" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Activate 'Full Screen Mode' During your Source Code Editing</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245408.aspx</link><pubDate>Wed, 20 Oct 2004 23:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245408</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245408.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245408</wfw:commentRss><description>&lt;p&gt;Okay, I admit this is a rather lame tip which can hardly qualify as 'insightful', however this is one of my favorite features of Visual Studio .NET (as well as previous editions of the Visual Studio product line) which many folks are (surprisingly) unaware of.  Under the View menu you will find a menu item named 'Full Screen'.  When activated, the only window displayed will be the active document.  This is especially helpful for those working on low resolution monitors, given that the size of your code window can shrink dramatically if you have too many windows docked within the IDE.  To escape from full screen, just click the Full Screen button floating over your code window.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003/2005&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245408" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Leverage the C# Preprocessor</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245316.aspx</link><pubDate>Wed, 20 Oct 2004 20:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245316</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245316.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245316</wfw:commentRss><description>&lt;p&gt;Like other languages in the C-family, C# supports a set of &lt;a href="http://msdn.microsoft.com/library/en-us/csref/html/vclrfPreprocessorDirectives.asp" target="_blank"&gt;'preprocessor' directives&lt;/a&gt;, most notably &lt;a href="http://msdn.microsoft.com/library/en-us/csref/html/vclrfdefine.asp" target="_blank"&gt;#define&lt;/a&gt;, #if and #endif (technically, csc.exe does not literally have a preprocessor as these symbols are resolved at the lexical analysis phase, but no need to split hairs&amp;#8230;). &lt;/p&gt; 

&lt;p&gt;The #define directive allows you to set up custom symbols which control code compilation.  Be very aware that unlike C(++), C#'s #define does not allow you to create macro-like code.  Once a symbol is defined, the #if and #endif maybe used to test for said symbol.  By way of a common example:&lt;/p&gt;

&lt;pre&gt;#define DEBUG
using System;

public class MyClass
{
  public static void Main()
  {
    #if DEBUG
      Console.WriteLine("DEBUG symbol is defined!");
    #endif
  }
}&lt;/pre&gt;

&lt;p&gt;When you use the #define directive, the symbol is only realized within the defining file.  However if you wish to define project wide symbols, simply access your project's property page and navigate to the "Configuration Properties | Build" node and edit the "Conditional Compilation Constants" edit field.  Finally, if you wish to disable a constant for a given file, you may make use of the #undef symbol. &lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003/2005&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245316" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Avoiding Type Name-Clashes using 'using'</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245297.aspx</link><pubDate>Wed, 20 Oct 2004 19:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245297</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245297.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245297</wfw:commentRss><description>&lt;p&gt;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 (very helpful for prevent name clashes). Assume you have the following two namespace definitions:&lt;/p&gt;
&lt;pre&gt;namespace My2DShapes
{
  public class Hexagon{} 
}

namespace My3DShapes
{
  public class Hexagon{} 
}&lt;/pre&gt;

&lt;p&gt;Now assume you wish to create an instance of the 3D Hexagon from the following application:&lt;/p&gt;

&lt;pre&gt;using My2DShapes;
using My3DShapes;

public class MyApp
{
  public static void Main()
  {
    // Error!  Which Hexagon?
    Hexagon h = new Hexagon();    
  }
}&lt;/pre&gt;

&lt;p&gt;This name clash can be resolved quite simply by building the following alias:&lt;/p&gt;

&lt;pre&gt;using My2DShapes;
using The3DHex = My3DShapes.Hexagon;

public class MyApp
{
  public static void Main()
  {
    // This really creates a new My3DShapes.Hexagon.
    The3DHex h = new The3DHex();    
  }
}&lt;/pre&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003/2005&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245297" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Build 'Consistent' .NET assemblies with FxCop</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245295.aspx</link><pubDate>Wed, 20 Oct 2004 19:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245295</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245295.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245295</wfw:commentRss><description>&lt;p&gt;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 by Microsoft, you will want to obtain a freely downloadable tool named fxcop.exe (FxCop may be downloaded from &lt;a href="http://www.gotdotnet.com/team/fxcop/" target="_blank"&gt;http://www.gotdotnet.com/team/fxcop/&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;This tool allows you to load any .NET binary and run it though a battery of tests which will check how your assembly stacks up against the coding standards upheld in the Base Class Libraries (including numerous .NET 'best practices').  Even better, you can create custom rules and ignore those you don't care about. This Windows Forms application is quite intuitive, however be aware that fxcop.exe ships with the requisite online help.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245295" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Simplified Interface Implementation a la VS .NET 2003</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245247.aspx</link><pubDate>Wed, 20 Oct 2004 18:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245247</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245247.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245247</wfw:commentRss><description>&lt;p&gt;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 six members.  While you could type in the member definitions by hand, you will save yourself time (and hand-cramps) by using the following shortcut.  Once you type the name of an interface at the type declaration, VS .NET pops up an invitation to (once again) hit the Tab key:&lt;/p&gt;

&lt;pre&gt;public class SomeClass 
  : ISomeInterface   // Message pops up to hit the Tab key&amp;#8230;
{&amp;#8230;}&lt;/pre&gt;

&lt;p&gt;Once you do, VS .NET will automatically write stub code for each and every member.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245247" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Simplified Event Handling a la VS .NET 2003</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245245.aspx</link><pubDate>Wed, 20 Oct 2004 18:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245245</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245245.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245245</wfw:commentRss><description>&lt;p&gt;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 then be aware of the correct signature of the delegate target method.&lt;/p&gt;
&lt;p&gt;To simplify matters, VS .NET 2003 will now automatically display the correct delegate name as well as write a prototype for the delegate target.  To try this out yourself, create a Windows Forms application and place a single Button type onto the designer. Next, type the following code within InitializeComponent():&lt;/p&gt;

&lt;pre&gt;this.Button1.Click +=	 // Message pops up to tell 
                       // you to hit the Tab key&amp;#8230;&lt;/pre&gt;
&lt;p&gt;Once you hit the Tab key, you will find the correct delegate is already in place.  Hit the Tab key again and you will receive a delegate target method of the correct signature.  Be aware that this shortcut works for any event, custom or standard (GUI-based or not).&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245245" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Integrate ildasm.exe into VS .NET 2002</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245242.aspx</link><pubDate>Wed, 20 Oct 2004 18:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245242</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245242.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245242</wfw:commentRss><description>&lt;p&gt;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 update the Tools menu manually. To do so, activate the Tools -&gt; External Tools menu item.  The 'Title' edit field allows you to supply the display name of your new menu item.  In the 'Command' filed, type in the path to ildasm.exe (for example, C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\ildasm.exe).  Finally, and most importantly, be sure to specify $(TargetPath) in the 'Arguments' field.  Once you have done so, you can simply activate this menu item and the assembly under development will automatically be loaded into ildasm.exe.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;More info on &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptutorials/html/ildasm_introduction.asp" target="_blank"&gt;ildasm.exe&lt;/a&gt;&lt;/i&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245242" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Add Custom .NET Assemblies to the Add Reference Dialog</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245239.aspx</link><pubDate>Wed, 20 Oct 2004 18:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245239</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245239.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245239</wfw:commentRss><description>&lt;p&gt;As you most likely know by now, the Add References dialog of Visual Studio .NET does &lt;i&gt;not &lt;/i&gt;list each and every assembly on your machine, does &lt;i&gt;not &lt;/i&gt;directly map to the Global Assembly Cache and does &lt;i&gt;not &lt;/i&gt;list your custom assemblies.  Typically this limitation is addressed by manually navigating to the *.dll of interest via the 'Browse' button.&lt;/p&gt;

&lt;p&gt;However, if you wish to force VS.NET to display your custom assemblies within in the list maintained by the Add Reference dialog, all you need to do is place a copy of the assembly within the 'PublicAssemblies' folder located under C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE.  Once you have done so, lo' and behold, your custom *.dlls are listed automatically.&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245239" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/IDE/default.aspx">IDE</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category><category domain="http://blogs.msdn.com/csharpfaq/archive/tags//default.aspx" /></item><item><title>Leverage C# Response Files at the Command Line</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245238.aspx</link><pubDate>Wed, 20 Oct 2004 18:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245238</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245238.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245238</wfw:commentRss><description>&lt;p&gt;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:&lt;/p&gt;
&lt;pre&gt;csc /r: MyAsm.dll;MyOtherAsm.dll /t: winexe /out: myApp.exe *.cs&lt;/pre&gt;
&lt;p&gt;To lessen your burden, the C# command line compiler supports the use of &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cscomp/html/vcerrspecifyresponsefile.asp" target="_blank"&gt;'response files'&lt;/a&gt;.  Simply put, response files are text files which contain all of the command line arguments you wish to feed into the compiler.  By convention, these files end with a *.rsp file extension.  Thus, assume you have a file named mySettings.rsp:&lt;/p&gt;
&lt;pre&gt;# Response files support comments.
/r: MyAsm.dll
/r: MyOtherAsm.dll
/t: winexe
/out: myApp.exe *.cs&lt;/pre&gt;
&lt;p&gt;With this, you can simply specify the name of the response file to use for the current compilation (via the @ symbol):&lt;/p&gt;
&lt;pre&gt;csc @mySettings.rsp&lt;/pre&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245238" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Be Aware of wincv.exe</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245236.aspx</link><pubDate>Wed, 20 Oct 2004 17:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245236</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245236.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245236</wfw:commentRss><description>&lt;p&gt;When you install the .NET SDK / VS.NET, you are provided with numerous stand alone programming tools, one of which is named wincv.exe (&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp" target="_blank"&gt;Windows Class Viewer&lt;/a&gt;).  Many developers are unaware of wincv.exe, as it is buried away under the C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin subdirectory (by default).&lt;/p&gt;
&lt;p&gt;This tool allows you to type in the name of a given type in the base class libraries and view the C# definition of the type.  Mind you, wincv.exe will not show you the implementation logic, but you will be provided with a clean snapshot of the member definitions.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245236" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Utilize the Server Explorer</title><link>http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245233.aspx</link><pubDate>Wed, 20 Oct 2004 17:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:245233</guid><dc:creator>CSharpFAQ</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/csharpfaq/comments/245233.aspx</comments><wfw:commentRss>http://blogs.msdn.com/csharpfaq/commentrss.aspx?PostID=245233</wfw:commentRss><description>&lt;p&gt;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 database Table or editing a stored procedure), you may not know that everything is dragable.  Let's say you know your application needs to interact with a machine's application event log.  Simply open the Event Logs tree and drag the Application icon onto a Forms designer.  VS .NET responds by declaring a member variable of type System.Diagnostics.EventLog and modifying InitializeComponent() appropriately:&lt;/p&gt;
&lt;pre&gt;this.eventLog1.Log = "Application";
this.eventLog1.MachineName = "MainHomeBox";
this.eventLog1.SynchronizingObject = this; &lt;/pre&gt;
&lt;p&gt;This same behavior holds true for any icon.  To take things out for a test drive, try dragging over an icon representing a stored procedure, Windows Service or Message Queue.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Tip from &lt;a href="http://www.intertechtraining.com/Instructors/Default.aspx?InstructorID=1" target="_blank"&gt;Andrew Troelsen&lt;/a&gt;&lt;br /&gt;
Posted by: &lt;a href="http://blogs.duncanmackenzie.net/duncanma" target="_blank"&gt;Duncan Mackenzie&lt;/a&gt;, MSDN&lt;br /&gt;
&lt;i&gt;This post applies to Visual C# .NET 2002/2003&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=245233" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/csharpfaq/archive/tags/Tips/default.aspx">Tips</category></item></channel></rss>