1

im a bit stuck right now and i hope u can quickstart me.

i Want a Method that i can for Example call like this:

string myString = GetSomething(typeof(string));

OR

DateTime dt = GetSomething(typeof(DateTime));

while GetSomething always returns the Type i give in as Argument. Is it possible to make this kind of signature? Or do i blow my head up for nothing right now?

Im atm stuck with this approach:

 public T GetSomething<T>(Type t ) where T : struct
4

1 回答 1

6

假设我已正确阅读您的问题,您只需要:

public T GetSomething<T> {
  return default(T);
}

DateTime dt = GetSomething<DateTime>();
于 2013-07-08T12:40:52.877 回答