Friday, February 04, 2005

My with C# 2.0

Introduction

This article/tutorial talks about My namespace which is
a new feature available with Microsoft .NET Framework 2.0,
and VB .NET 2005 only feature.

About My

With the latest release of Visual Studio .NET 2005
codenamed Whidbey, VB .NET 2005 has been shipped
with one extra class in .NET Framework 2.0 BCL.
The My namespace’s with VB .NET 2005 will help
to write difficult code with a lot of ease.

For example, accessing computer information,
reading computer clock, opening ports, accessing
network, files etc.

Since this most fascinating feature is VB .NET 2005
specific which aimed to help VB .NET developers, and C#
geeks still has to write code for above mentioned tasks,
as like before.

Accessing My with C#

Besides having the total control and writing the code on
your own as being the real C# developer, My namespace can
be accessed and used in C# programs.

The idea of accessing My lies in the core .NET Framework 2.0 BCL
Base Class Library), and My namespace has its implementation in
an assembly named Micrisoft.VisualBasic.dll and uses Microsoft.VisualBasic.MyServices namespace.

By having reference to this assembly, the functionality of My
namespace can be used with C# also.

Code Example

The example shows how to call My in C#

Step - 1 Run Visual Studio .NET 2005 (Whidbey)
File --> New --> Project -->Visual C# --> Console Application

Step - 2 Add Reference to Microsoft.VisualBasic.dll under References



Step - 3 Add the following line under using directive

using Microsoft.Visualbasic.MyServices;

and then add the code to call the functionality

Click to view the code

Step - 4 Run the application and see the output.



Conclusion

This article/tutorial briefly introduced the My namespace and how to access My with C#.

Another point is that why My is VB .NET 2005 only feature, the reason I can think is Visual Basic is the language which has been greatly recognized for its IDE and Intellisense features and this is all what satisfies the term RAD and this is why it is available with VB .NET 2005 (by default) and not with C#. VB .NET Code Editor Window recognizes My and it is a Language Enhancement with VB .NET 2005.

Since, My namespace is the part of .NET Framework 2.0 BCL (Base Class Library), implemented in Microsoft.VisualBasic.dll assembly, under the namespace Microsoft.VisualBasic.MyServices namespace, any C# developers can also take advantage of that by having a reference to the Microsoft.VisualBasic.dll and invoking the functionality from Microsoft.VisualBasic.MyServices namespace.

1 comment: