there’s no ambiguity, since the first can only be called through the type name, and the second can only be called through an instance.

A:

It is true that there would be no ambiguity between the two functions as far as a compiler is concerned. There would, however, be a considerable potential for confusion on the part of the user. It would be tough to find the right method in documentation, and once you did, hard to be sure that you are calling the right version (ie you could accidentally call the static version when you wanted the instance version).

I disagree with your belief that a user would get confused between the two function calls (at least not in C#).

To call your static function you would have to invoke it as Test.Process();

To call your instance of the funtion you would have to us an instance:

new Test().Process();

or

Test obj = new Test();

obj.Process();

I can’t see how you could get confused here. I would also assume that the static function would perform the same functionality as the instance version of it, but the static probably handles the creation and destuction of the object. IE I would expect that the following would do the same:

Guid.NewGuid();

New Guid().NewGuid();

Personally I think this is a time saver for end users of the component.

There is actaully a very simple reason why it is illegal. In C# it is legal to have a local variable that is the same as a class name. This means that if an instance member was to be named the same as static member there would be an ambiguity when a local variable had the same name as the class it represents.

So consider the following legal C# code:

public class TestClass

{

public TestClass(){}

public static void MyStaticMethod()

{}

public void MyInstanceMethod()

{}

}

public class StartUp

{

public static Int32 Main(String[] args)

{

TestClass TestClass = new TestClass();

TestClass.MyInstanceMethod();

TestClass.MyStaticMethod();

return 0;

}

}

If MyInstanceMethod & MyStaticMethod names were change to be the same there would be an ambiguity.

Why it is legal to have have a local variable that is the same as a class name in C#?? why not in VB.NET and other languages? If we don’t allow name of a local variable that is the same as a class name then this confusion won’t happen.