C# and .NET interview Question - Explanation on Generic?
Shivprasad Koirala
class Check<UNKNOWNDATATYPE> { public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j) { if (i.Equals(j)) { return true; } else { return false; } } }
class Program { static void Main(string[] args) { Check ObjCheck = new Check(); //here i have defined int datatype bool b1 = ObjCheck.Compare(1, 1); Check Obj1 = new Check(); //here i have defined string datatype bool b2 = Obj1.Compare("feroz", "kalim"); Console.WriteLine("Numeric Comparison Result:" + b1); Console.WriteLine("String Comparison Result:"+ b2); Console.ReadLine(); } }
class Program { static void Main(string[] args) { Check ObjCheck = new Check(); bool b1 = ObjCheck.Compare(1, 1); Check Obj1 = new Check(); bool b2 = Obj1.Compare("feroz", "kalim"); Console.WriteLine("Numeric Comparison Result:" + b1); Console.WriteLine("String Comparison Result:"+ b2); Console.ReadLine(); } } class Check<UNKNOWNDATATYPE>{public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j){if (i.Equals(j)){return true;}else{return false;}}}
Please click here to see more C#/ .NET interview questions