Chris Brickhouse Chris Brickhouse - 3 months ago 9
ASP.NET (C#) Question

cannot expose class in c#

This may seem like a beginner question, and it kind of is since this is my first large c# project conversion. Currently converting a large project from vb.net to c#, I understand c# syntax pretty well and the conversion is going pretty smoothly. My one question is - in vb.net I could expose a class with the import statement as such:

Imports DataAccessLayer.DataAccess


and say there is a method called GetDataTable in the DataAccess class, I can just call it by using GetDataTable(params)

Now, with C#, I can only do

Using DataAccessLayer;


and can't expose the DataAccess class, just the DataAccessLayer namespace and have to do DataAccess.GetDataTable(params), which will obviously add a lot of extra code to the project if I have to do that anywhere.

Is there any way to expose the class and not just the namespace? This is my constructor

namespace DataAccessLayer
{
public class DataAccess
{
}
}


Thanks in advance!

Answer

If you are using C# v6 or above, you can import a static class like this:

using static Namespace.StaticClass;

So you can do the same for your class:

using static DataAccessLayer.DataAccess;
Comments