Interesting question. Type safety is preserved here. Behaviour is alike global and local variables. In MyMethod type T is unambiguous. We can also create and return new instance of MyClass as follows:
public class MyClass<T>
{
public T MyField;
public T MyProp { get; set; }
public MyClass<T> MyMethod<T>(T k)
{
return new MyClass<T>();
}
}
The program:
static void Main()
{
var c = new MyClass<int>(); //T is int
c.MyField = 1;
c.MyProp = 1;
var myClass = c.MyMethod("2");
myClass.MyField = "2";
myClass.MyField = "4";
}
There is no compilation error and it shouldn't be, because type safety is preserved. Program can be compiled. There is no ambiguity.
The warning should be there, because T overrides its class level counterpart and there is no simple way in MyMethod to obtain that global T. It also obscures legibility.
MSDN says about flexibility and good practice in Generic Methods (C# Programming Guide):
If you define a generic method that takes the same type parameters as the containing class, the compiler generates warning CS0693 because within the method scope, the argument supplied for the inner T hides the argument supplied for the outer T. If you require the flexibility of calling a generic class method with type arguments other than the ones provided when the class was instantiated, consider providing another identifier for the type parameter of the method.