What is the use of 'in' keyword in C#?

1.1k views Asked by At

What is the use of in keyword?

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

1

There are 1 answers

0
NeoAsh On

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.