Σημείωση
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να συνδεθείτε ή να αλλάξετε καταλόγους.
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να αλλάξετε καταλόγους.
The
You use the ref keyword in the following contexts:
- In a method signature and in a method call, to pass an argument to a method by reference.
public void M(ref int refParameter) { refParameter += 42; } - In a method signature, to return a value to the caller by reference. For more information, see
ref return.public ref int RefMax(ref int left, ref int right) { if (left > right) { return ref left; } else { return ref right; } } - In a declaration of a local variable, to declare a reference variable.
public void M2(int variable) { ref int aliasOfvariable = ref variable; } - As the part of a conditional ref expression or a ref assignment operator.
public ref int RefMaxConditions(ref int left, ref int right) { ref int returnValue = ref left > right ? ref left : ref right; return ref returnValue; } - In a
structdeclaration, to declare aref struct. For more information, see therefstructure types article.public ref struct CustomRef { public ReadOnlySpan<int> Inputs; public ReadOnlySpan<int> Outputs; } - In a
ref structdefinition, to declare areffield. For more information, see thereffields section of therefstructure types article.public ref struct RefFieldExample { private ref int number; } - In a generic type declaration to specify that a type parameter
allows ref structtypes.class RefStructGeneric<T, S> where T : allows ref struct where S : T { // etc }
Συνεργαστείτε μαζί μας στο GitHub
Η πηγή για αυτό το περιεχόμενο βρίσκεται στο GitHub, όπου μπορείτε επίσης να δημιουργήσετε και να ελέγξετε ζητήματα και αιτήματα έλξης. Για περισσότερες πληροφορίες, ανατρέξτε στον οδηγό συνεισφερόντων.