D
D
Daniel Demidko2018-05-22 12:29:55
C++ / C#
Daniel Demidko, 2018-05-22 12:29:55

Write ref in C#?

I remember exactly that in one of the announcements of the next version of C #, it slipped that now it is not necessary to write ref when passing parameters, that is, you can write like this:

void Test(ref int n) {}

void Action 
{
    int n = 4;
    Test(n); // вместо Test(ref n)
}

I then immediately checked this example and it worked.
But now, after some time, I can't find any information about it, and this code doesn't work (C# 7.3), why?
Found!
https://habr.com/post/113586/
This only works for some calls - "the ref keyword can be omitted when calling a method through COM Interop"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-05-22
@DanielDemidko

You are confusing something, the requirement, as it was, remains.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question