How can I import a static method from another c# source file and use it without "dots"?
like:
foo.cs
namespace foo
{
public static class bar
{
public static void foobar()
{
}
}
}
Program.cs
using foo.bar.foobar; // <= can't!
namespace Program
{
class Program
{
static void Main(string[] args)
{
foobar();
}
}
}
I can't just foobar();
, but if I write using foo;
on the top and call foobar()
as foo.bar.foobar()
it works, despite being much verbose. Any workarounds to this?
This is the accepted answer, but note that as the answer below states, this is now possible in C# 6
You can't
static methods needs to be in a class by design..