Last post May 20, 2021 09:53 AM by PatriceSc
May 13, 2021 01:52 PM|dileep Sanker|LINK
I have one function name as MyGenricsWorld().I want to write a list as
obj1=new List<T>(); where T=Student
obj1=new List<Employee>(); where T=Employee
Is possible to write the above two different way as mentioned.Both Student and Employee are two classes.
Thanks & Regards,
May 13, 2021 02:26 PM|mgebhard|LINK
The Generic method syntax and LINQ syntax is incorrect. It is hard to figure out what you are trying to do given the code.
I think that you'll be interested in reading the C# programming guide to learn how to work with Generics and LINQ.
May 14, 2021 03:39 AM|PaulTheSmith|LINK
What are you trying to do?
The "code" you have shown makes no sense and would not compile.
May 20, 2021 09:53 AM|PatriceSc|LINK
Seems you are trying to mix using generics with workarounds you could use when not having this feature.
The basic idea is to write a MyMethod<T> (or MyClass<T>), T being a parameter. Then you can use MyMethod<Employee> or MyMethod<Student> where needed.
As the type is not know, the code needs to be fairly general. if posisble you can have constraints on the T type allowing to write more specialized code.