About 14,800,000 results
Open links in new tab
  1. c# - Why use the 'ref' keyword when passing an object? - Stack Overflow

    If I am passing an object to a method, why should I use the ref keyword? Isn't this the default behaviour anyway? For example: class Program { static void Main(string[] args) { Te...

  2. When to use ref and when it is not necessary in C#

    Mar 12, 2009 · The ref keyword signifies that you're passing the actual pointer to the location and updating that pointer in the outside function, so the value in the outside function will change. E.g. the …

  3. c# - What's the difference between the 'ref' and 'out' keywords ...

    Dec 23, 2008 · ref means that the value in the ref parameter is already set, the method can read and modify it. Using the ref keyword is the same as saying that the caller is responsible for initializing the …

  4. .net - How to pass this by ref in C#? - Stack Overflow

    May 24, 2022 · 1 Underneath C#/.NET achieves Pass by Object by passing a reference to an object by Value. However, the rules above correctly describe the observable semantics and effects. 2 Unlike …

  5. C# ref is it like a pointer in C/C++ or a reference in C++?

    Apr 25, 2013 · In C#, when you see something referring to a reference type (that is, a type declared with class instead of struct), then you're essentially always dealing with the object through a pointer. In …

  6. What is the use of "ref" for reference-type variables in C#?

    But with reference-types, like classes, even without the ref keyword, a reference is passed to the method, not a copy. So what is the use of the ref keyword with reference-types? Take for example:

  7. c# - Assigning out/ref parameters in Moq - Stack Overflow

    Is it possible to assign an out / ref parameter using Moq (3.0+)? I've looked at using Callback(), but Action<> does not support ref parameters because it's based on generics. I'd also preferably like to …

  8. c# - Alternative to using ref in foreach? - Stack Overflow

    bool success = Modify(ref obj); I get "cannot use obj as a ref / out because it is a 'foreach iteration variable". I understand that foreach uses an immutable iterator and that's why this doesn't work. My …

  9. pointers - using ref with class C# - Stack Overflow

    Jun 9, 2009 · Jon Skeet has written an excellent article about parameter passing in C#, which compares and contrasts value types, reference types, passing by value, passing by reference (ref), and output …

  10. c# - When to use in vs ref vs out - Stack Overflow

    out and ref parameters are marshaled differently when dealing with interop code Also, as an aside, it's important to note that while reference types and value types differ in the nature of their value, every …