当前位置:网站首页>How to determine whether T is a value type in a generic type or a reference class- How to determine whether T is a value type or reference class in generic?

How to determine whether T is a value type in a generic type or a reference class- How to determine whether T is a value type or reference class in generic?

2022-06-13 00:36:00 Technology feast

problem :

I have a generic method behavior of which depends on T is reference type or value type. I have a generic method whose behavior depends on T Is it a reference type or a value type .It looks so: It looks like this :

T SomeGenericMethod <T> (T obj){  if (T is class) //What condition I must write in the brackets?   //to do one stuff  else //if T is a value type like struct, int, enum and etc.   //to do another stuff}

I can't duplicate this method like: I can't copy this method like this :

T SomeGenericMethod <T> (T obj) where T : class{ //Do one stuff}T SomeGenericMethod <T> (T obj) where T : struct{ //Do another stuff}

because their signatures are equal. Because their signatures are equal .Can anyone help me? Who can help me ?


Solution :

Reference resources : https://stackoom.com/en/question/Vnyi
原网站

版权声明
本文为[Technology feast]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280601540081.html