C# .NET - Object type parameter gets converted to another type

Asked By anbu n on 19-Mar-12 11:39 AM
  public static int AddmastrContent(Setting_Master obj_Entity)
    {
      Master_general_provider obj_prov = new Master_general_provider();
      return obj_prov.AddNew(obj_Entity);
    }

--------------

    Setting_Master _enty_sett = new Setting_Master();
    public int AddNew(object objInfo)
    {
      _enty_sett = (Setting_Master)objInfo;
      
      string val;

      val = "1";

      return Convert.ToInt32(val);    
      
    }


-----------------------


here
in above code Setting_Master is a class ----
first
function calls next function -- > AddNew(object objInfo)
here the parameter
is object type ,

but what happens
in below code :

 _enty_sett = (Setting_Master)objInfo; 


is this any oops concept ?


[)ia6l0 iii replied to anbu n on 19-Mar-12 10:12 PM
Object is the base type. When you send a Setting_Master as Object, it loses its specific type. 

And then as this is a reference type, you are using an "Explict Cast" to convert from the base type to the specific type (Setting_Master).