Good code. Cheers,
Chike --- On Wed, 5/18/11, Cerebrus <[email protected]> wrote: From: Cerebrus <[email protected]> Subject: [DotNetDevelopment] Re: Based on calling time Type, have to return the list of the same type To: "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" <[email protected]> Date: Wednesday, May 18, 2011, 8:56 AM Generic methods are not usually designed like this. If they had to apply cases based on the constructed type, their utility would be very limited because it would necessitate adding new code everytime the generic method was to be used with a new Type. In your getList() method, "T" is an open type. When you try to add a Product to the list object, it refuses to compile because at that time T is not compatible with class Product. Instead, you need to look back at the place where you *know* that T is a Product. That place is the calling function (Main()) and that should be the place where you create and pass on various types of objects to the single generic method. This necessitates passing the types as a parameter. I have posted a modified but simplistic example of your code at http://pastebin.com/w7e1Jn6J. Review it and post back if you have further doubts. -- You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en or visit the group website at http://megasolutions.net -- You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en or visit the group website at http://megasolutions.net
