-1

What is the use of in keyword?

C# 7.0 introduce new keyword which is in. Let's share usability of this new keyword.

Patrick Hofman
  • 148,824
  • 21
  • 237
  • 306
NeoAsh
  • 863
  • 1
  • 7
  • 11
  • 4
    `in` has not been introduced in C# 7.0 but in C# 1.0 (`foreach`). New contexts have been added in C# 3.0 (LINQ), C# 4.0 (contravariance) and C# 7.2 (parameter modifier). – György Kőszeg Nov 21 '18 at 08:58

1 Answers1

2

C# 7 introduced the in modifier. It got the name by being the opposite of out keyword. It makes the reference (alias) read only; and the caller does have to initialize the value.

void DoSomeTask(in Employee emp)
{
    //emp can't be altered here.
}

It helps to restrict make any modification in object accidentally.

NeoAsh
  • 863
  • 1
  • 7
  • 11