Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Added an external reference but cannot use!

Posted on 2011-09-07
3
Medium Priority
?
230 Views
Last Modified: 2012-05-12
Hi,

I'm very new to C# and not doing to well. I have added an external reference that is now showing in the solution explorer window. The thing is how do I reference it's properties and methods?

Thanks,
0
Comment
Question by:mcs26
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
yesthatbob earned 2000 total points
ID: 36498025
To get the namespaces and classes exposed by the reference, right-click on it in the solution explorer and select View in Object Browser. You can then simply refer to the classes defined in the reference in your code using the fully qualified namespace, or you can add a using statement at the top of your class file to reference the namespace as a shortcut. Here's an example of using the fully qualified namespace:

using System;

namespace ExampleCode
{
	class RegExExample
	{
		System.Text.RegularExpressions.Regex myRegEx = new System.Text.RegularExpressions.Regex("what");
		System.Text.RegularExpressions.Match myMatch = myRegEx.Match("whatever");
	}
}

Open in new window


And an example of the using statement:

using System;
using System.Text.RegularExpressions;

namespace ExampleCode
{
	class RegExExample
	{
		Regex myRegEx = new Regex("what");
		Match myMatch = myRegEx.Match("whatever");
	}
}

Open in new window


0
 

Author Comment

by:mcs26
ID: 36498163
Hi yesthatbob,

Thanks for the reply. Is there a way to reference all the classes in the refrence in one go?

Thanks again,
M
0
 
LVL 4

Expert Comment

by:yesthatbob
ID: 36498252
Well, no. You can reference all of the namespaces with individual using statements, but this is generally bad form - you should only add a using for the namespace you will actually be using. As for classes, you only refer to a class when you need it in code, so there's no need to reference "all of the classes" before hand.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question