tagged [ref]

Why does the following code compile without errors?

Why does the following code compile without errors? I was messing around with my C# project a little bit and I was surprised to see this code compiles: Flipping it the other way around, like `Action a...

Is there a difference between passing a function to a delegate by ref?

Is there a difference between passing a function to a delegate by ref? I came upon this piece of C# code that uses delegates and passes the function to the delegate by reference... ``` delegate bool M...

27 Jan at 11:18

Why ref structs cannot be used as type arguments?

Why ref structs cannot be used as type arguments? C# 7.2 [introduced](https://learn.microsoft.com/en-us/dotnet/csharp/reference-semantics-with-value-types) `ref struct`s. However, given a `ref struct`...

27 Nov at 11:19

Get a reference to a struct inside array

Get a reference to a struct inside array I want to modify a field of a struct which is inside an array without having to set entire struct. In the example below, I want to set one field of element 543...

20 Aug at 18:41

Impact of using the 'ref' keyword for string parameters in methods in C#?

Impact of using the 'ref' keyword for string parameters in methods in C#? As a programmer who don't have a good idea about the .NET pipeline, I was wondering if using ref strings as parameters are goo...

21 Mar at 19:57

Interesting interview exercise result: return, post increment and ref behavior

Interesting interview exercise result: return, post increment and ref behavior Here's a simple console application code, which returns a result I do not understand completely. Try to think whether it ...

22 Apr at 11:28

PL/SQL print out ref cursor returned by a stored procedure

PL/SQL print out ref cursor returned by a stored procedure How can I fetch from a ref cursor that is returned from a stored procedure (OUT variable) and print the resulting rows to STDOUT in SQL*PLUS?...

22 Dec at 22:34

What is ref struct in definition site

What is ref struct in definition site I think I've heard a term "ref like struct" in GitHub some time ago. Now that I have my hands on latest C# version (7.3), I could finally test it my self. So this...

24 Aug at 14:14

Why is list when passed without ref to a function acting like passed with ref?

Why is list when passed without ref to a function acting like passed with ref? If I did not get this terribly wrong, this behaviour is strange for me. Rather than explaining, I'll post a sample code b...

2 Jul at 22:6

Ref Abuse: Worth Cleaning Up?

Ref Abuse: Worth Cleaning Up? I have inherited some code that uses the keyword extensively and unnecessarily. The original developer apparently feared objects would be cloned like primitive types if w...

4 Sep at 23:24

C# Cannot use ref or out parameter inside an anonymous method body

C# Cannot use ref or out parameter inside an anonymous method body I'm trying to create a function that can create an Action that increments whatever integer is passed in. However my first attempt is ...

21 Nov at 02:25

Alternative to using ref in foreach?

Alternative to using ref in foreach? I have a modifying method with a signature like that will make modifications to `obj` and indicate succes with it's return value. `Modify` is not reassigning the r...

28 Jul at 19:27

C#6/C++ ref keyword error

C#6/C++ ref keyword error I tried VS2015 with my exisiting solution and I get some valid new errors (like unreachable code that the compiler didn't catch before), but I also get an error for example o...

18 Nov at 09:52

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

When to use ref and when it is not necessary in C# I have a object that is my in memory state of the program and also have some other worker functions that I pass the object to to modify the state. I ...

11 Mar at 19:41

How to pass List<DerivedClass> when param type is List<BaseClass>?

How to pass List when param type is List? How can i pass a list which is a list of DerivedObjects where the Method is expecting a list of BaseObjects. I am converting the list `.ToList()` and am wonde...

4 Oct at 05:30

The performance cost to using ref instead of returning same types?

The performance cost to using ref instead of returning same types? Hi this is something that's really bothering me and I'm hoping someone has an answer for me. I've been reading about `ref` (and `out`...

25 May at 20:19

Sending an HTTP POST request on iOS

Sending an HTTP POST request on iOS I'm trying to send an HTTP Post with the iOS application that I'm developing but the push never reaches the server although I do get a code 200 as response (from th...

When is it more efficient to pass structs by value and when by ref in C#?

When is it more efficient to pass structs by value and when by ref in C#? I've researched a bit and it seems that the common wisdom says that structs should be under 16 bytes because otherwise they in...

7 Mar at 18:4

Keep a TypedReference alive out of method block without returning it

Keep a TypedReference alive out of method block without returning it I want to premise that this question's purpose is checking if there's at least one way, even if through the most unsafe hack, to ke...

23 May at 12:16