I’ve talked a lot about improved COM interop in C# 4.0 and how much easier it is now to work with Office applications. This time I want to share some tips and tricks on how you can convert Visual Basic for Applications (VBA) macros to C# 4.0 by using Office 2010 and Visual Studio 2010.
Use the System.Environment class.
Specifically the GetEnvironmentVariable and SetEnvironmentVariable methods.
Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to set environment variables is new to the Whidbey release,
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.
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’.
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.
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).
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,
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.
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.