1

I am a new learner of c#. I need some example about using of in and out keyword. I understand these concepts but I do not understand what would happen if we did not use them.

Hesan Mahdi
  • 137
  • 9
  • From [here](https://learn.microsoft.com/en-us/dotnet/standard/generics/covariance-and-contravariance): *"Covariance and contravariance are terms that refer to the ability to use a more derived type (more specific) or a less derived type (less specific) than originally specified. Generic type parameters support covariance and contravariance to provide greater flexibility in assigning and using generic types."* – Robert Harvey Dec 30 '21 at 01:23
  • Did you read [c# - When should I use out parameters? - Stack Overflow](https://stackoverflow.com/questions/1169786/when-should-i-use-out-parameters?noredirect=1&lq=1) ? – user202729 Dec 30 '21 at 01:24
  • If you don't use them, what would happen is that you would not benefit from the greater flexibility in assigning and using generic types. – Robert Harvey Dec 30 '21 at 01:24
  • you will know when you need them, at the moment you dont need them. – pm100 Dec 30 '21 at 01:25
  • The other one is [c# 7.2 - Why would one ever use the "in" parameter modifier in C#? - Stack Overflow](https://stackoverflow.com/questions/52820372/why-would-one-ever-use-the-in-parameter-modifier-in-c) – user202729 Dec 30 '21 at 01:39
  • Covariance and contravariance are hardly important topics for _new learners of C#_. If you ask an expert how they work, expect a pause before the explanation begins; they are not simple topics. Using the `out` keyword as a parameter modifier is quite common (particularly with the _TryGetXxx_ pattern) and is worth learning for a new learner – Flydog57 Dec 30 '21 at 02:53

0 Answers0