I am trying to create a method that needs to take an interface as a reference type. Firstly is this even possible?
Basically my method needs to be called twice and the first param will be different types but both implement the interface, so I have something like this
|
So you can see that the first param in validate is of different types but both methods call the new method, whose first param is an interface.
This approach does not work it throws a complier error.
Can anyone point me in the right direction please?
Thanks
Mike GoldPosted Feb 16, 2011, 11:58 PM
Also if CMS.TreeEngine.TreeNode is a class and SkuInfo is a class, they are already reference types, so you don't need ref.
the exception is if either TreeNode or SkuInfo are structs. But in general, you do not want to put interfaces on structs if you don't have to. You are better off making your struct a class. Below is a good thread to read on the reason:
http://stackoverflow.com/questions/63671/is-it-safe-for-structs-to-implement-interfaces
Amit ChoudharyPosted Feb 16, 2011, 7:00 AM
Yes you are right it will give you the compilation error.. cause you cannot use ref and out with Interface reference.. try without using ref and out.
also you have used it like:
which is also not possible until you assign a reference of its inherited class.
Thanks.