[Solved] Re-casting c# variables with a different class


Couldn’t you refactor it so that you have a generic method that takes a WebResponse?

public T Deserialize<T>(WebResponse response)
    where T: new() // ensure that any type of T used has a parameterless constructor
{
    string r = "";
    using (StreamReader sr = new StreamReader(res.GetResponseStream()))
    {
        r = sr.ReadToEnd();                        
    }
    JavaScriptSerializer js = new JavaScriptSerializer();
    return js.Deserialize<T>(r);
}

Usage:

var student= Deserialize<student>(res);

solved Re-casting c# variables with a different class