Kamerton
Kamerton

Reputation: 315

Using return with method inline

I want to inline a method with a switch block.

If I use the return in switch statements, will it break the ParentMethod execution?

void ParentMethod()
{
    InliningMethod(myEnum.SomeValue);

    //do some after inline for test case
    Console.WriteLine("Will this have been writed?"); 
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
void InliningMethod(MyEnum value)
{
    switch(myEnum)
    {
        case MyEnum.SomeValue:
            return; //will it have been moved in ParentMethod?
        default: break;       
    }
    //do some
}

Upvotes: 0

Views: 192

Answers (2)

arvind singh
arvind singh

Reputation: 1

Inline method is just a style to write method in less code, it doesn't change execution principle. So, "return statement" inside inline method will not break parent method.

Upvotes: 0

nvoigt
nvoigt

Reputation: 77304

Inlining does not mean the code just gets copied over. The compiler will get it right, the return only exits the method it's in, whether the compiler later inlines it or not.

Upvotes: 2

Related Questions