The given expression is never of the provided warning.


When you try to getting type of Generic variable “T” you get this warning.Here is the sample :

class CauseWarning {     public void make<T>(T value)     {     if (typeof(T) is Test)         Console.Write("Something");     } } public class Test { }

Here is the solution:


class CauseWarning {     public void make<T>(T value)     {     if (typeof(T).IsAssignableFrom(typeof( Test)))         Console.Write("Something");     } } public class Test { }

Type.IsAssignableFrom Method Determines whether an instance of the current Type can be assigned from an instance of the specified Type.true if the c parameter and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c supports. false if none of these conditions are the case, or if c is a null reference.

Advertisements

About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: