where T : the meaning of class

 public static T DeserializeJsonToObject<T>(string json) where T : class
        {
            JsonSerializer serializer = new JsonSerializer();
            StringReader sr = new StringReader(json);
            object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
            T t = o as T;
            return t;

        }


This is the parameter type constraint, specifying that T must be of type Class.

 

There are five types of type parameter constraints supported by .NET:
where T : struct | T must be a struct type
where T : class                                 | T must be a Class type
where T : new() | T must have a no-argument constructor
where T : NameOfBaseClass | T must inherit a class named NameOfBaseClass
where T : NameOfInterface | T must implement an interface named NameOfInterface


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326080950&siteId=291194637