Global cases to the entire application

Global cases to the entire application

How can I make a class global to the entire application? In C++, could I use the "extern" keyword to aid in handling this?

    Requires Free Membership to View

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchWinDevelopment.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchWinDevelopment.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

The concept of global classes in C# is really just a simple matter of referencing the appropriate assembly containing the class. Once you have reference the needed assembly, you can refer to the class of choice either by it's fully qualified Type name, or by importing the namespace that contains the class.

If you want to import the namespace you can do so by the "using <Namespace>;" statement at the top of your source file. You will find examples of this in any C# source file generated when you insert a class, user control, or form into your project. Simply look to the top of the file to see lines such as "using System;" This allows the compiler to look into the specified namespace to find the Type you are after.

If you do not want to import the namespace by the "using" statement, you can simply refer to the Type using its fully qualified name. An example of this might be System.String. If this was a class you have defined it might appear like this. YourBusiness.YourApplication.YourClass.

If you are interested in reading up on namespaces, then open up the MSDN library or go online and lookup the "using" statement/keyword with C# as your filter. You should find all the reference and more in MSDN.

Cheers!

This was first published in November 2004