C# Added an external reference but cannot use!

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,
mcs26Asked:
Who is Participating?
 
yesthatbobConnect With a Mentor Commented:
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
 
mcs26Author Commented:
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
 
yesthatbobCommented:
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
All Courses

From novice to tech pro — start learning today.