Answered by:
out parameter without a method

Question
-
You may please look at this area
http://msdn.microsoft.com/en-us/library/9eekhta0.aspx
please note
public interface IEnumerable<out T> : IEnumerable
We know that ban "out" parameter can only be used to pass values out of a method
Now if we code some thing as
public class My_Good_Class<T>: IEnumerable<out T> {// .....etc}
How are we using the out parameter withot using a method ??
Wednesday, July 31, 2013 5:54 AM
Answers
-
Question: What exactly are you trying to do? We have "out IEnumerable<T>" as parameter but never "IEnumerable<out T>", let alone assign it as a type.
"out" is decorator to a parameter, telling the compiler what to do with the parameter, but it's neither a type or a part of a type. You may spend some time to make your mind clear about the concepts involved, then try to ask again.
- Marked as answer by Caillen Wednesday, August 7, 2013 4:24 AM
Wednesday, July 31, 2013 6:22 AMAnswerer -
That is not a out Parameter.
This is a out Generic modifier. Similar Syntax, totally different kind of beast. It deals with a very advanced form of Polymorphy called "Covarriance":
http://msdn.microsoft.com/en-us/library/dd469487.aspx
Basically it goes:
Because the generics type was marked with out (is covariant) and because you could store a String in an Object Reference, you can store a Sample<String> Instance in a Sample<Object> Reference.
Sounds logical, but is only a recent addition.
Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.
- Proposed as answer by cheong00Editor Wednesday, July 31, 2013 7:32 AM
- Marked as answer by Caillen Wednesday, August 7, 2013 4:24 AM
Wednesday, July 31, 2013 7:08 AM
All replies
-
Question: What exactly are you trying to do? We have "out IEnumerable<T>" as parameter but never "IEnumerable<out T>", let alone assign it as a type.
"out" is decorator to a parameter, telling the compiler what to do with the parameter, but it's neither a type or a part of a type. You may spend some time to make your mind clear about the concepts involved, then try to ask again.
- Marked as answer by Caillen Wednesday, August 7, 2013 4:24 AM
Wednesday, July 31, 2013 6:22 AMAnswerer -
That is not a out Parameter.
This is a out Generic modifier. Similar Syntax, totally different kind of beast. It deals with a very advanced form of Polymorphy called "Covarriance":
http://msdn.microsoft.com/en-us/library/dd469487.aspx
Basically it goes:
Because the generics type was marked with out (is covariant) and because you could store a String in an Object Reference, you can store a Sample<String> Instance in a Sample<Object> Reference.
Sounds logical, but is only a recent addition.
Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.
- Proposed as answer by cheong00Editor Wednesday, July 31, 2013 7:32 AM
- Marked as answer by Caillen Wednesday, August 7, 2013 4:24 AM
Wednesday, July 31, 2013 7:08 AM -
You're right. Never implemented things using this feature and not aware that it exist.Wednesday, July 31, 2013 7:32 AMAnswerer