The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by reference is that any change to the parameter in the method is reflected in the underlying argument variable in the calling method. The value of a reference parameter is always the same as the value of the underlying argument variable.
Questions tagged [ref]
1394 questions
-2
votes
1 answer
How do I pass a parameter by ref to a member variable?
Quite new to C#, from a long time ago C++ background and so I seem to be having my trouble transitioning away from pointers to ref in C#.
I have a class (EColour) which I create using the constructor shown.
I assign (or at least try to) a reference…

J S
- 3
- 1
- 1
-2
votes
1 answer
How return ref var from function
I just begin to learn Go, and have a problem with returning ref vars from function
I have a function to get rows from a DB table:
func getData(query string, db *sql.DB) *sql.Rows {
rows, err := db.Query(query)
if err != nil {
…

Vasilij Altunin
- 754
- 1
- 5
- 18
-2
votes
5 answers
How do I assign reference field
public class SomeClass
{
public X x;
string name;
string someInfo;
public SomeClass(string name,...)
{
//....
}
}
public class X
{
}
SomeClass a = new SomeClass(~~~);
SomeClass b = new SomeClass(~~~);
a.x = new X(); …

angdroid
- 81
- 6
-2
votes
3 answers
Why some C# library functions don't follow the "ref" parameter passing convention
There are many examples, let's take array copy method as an example. The signature of the Array.Copy is method is as below
public static void Copy (Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long…

John Z. Li
- 1,893
- 2
- 12
- 19
-2
votes
1 answer
react easy example of using ref callback
Could I please ask you to write some easy example of using react ref callback? I want to see, how can I take an input value after I push a button using ref callback, because I don't get it and I can't find a full example.
For example I have some…

FKa
- 47
- 1
- 7
-2
votes
2 answers
Why passing string to a method behaves unlike List
I was reading a code that made me stop at some line:
List

mshwf
- 7,009
- 12
- 59
- 133
-2
votes
3 answers
What adress does "&ref_var" points to?
Consider the following code:
std::vector &MyClass::getVector() const
{
return (myVec);
}
void aFunc()
{
std::vector *vec = &myClassInstance.getVector();
}
What adress does vec points to? Does it points to the very address of myVec in the…

Krapow
- 611
- 6
- 26
-2
votes
3 answers
Ref and Out Parameters Questions
I thought I understood the difference, but now I'm not so sure. I've read the technical answer several times but I'm not understanding what is happening. I have this example.
class Program
{
static void Main()
{
int val =…

christopher clark
- 2,026
- 5
- 28
- 47
-2
votes
2 answers
c# parameter passing in ref with class field
I want to swap the field in the ConvexHull class just like swap( points[0], points[1] ).
How do I have to do?
public class ConvexHull
{
List points;
public void run ()
{
Point.swap ( ref points[ 0 ], ref points[ 1 ] ); …

BokukPark
- 29
- 5
-2
votes
3 answers
Modification of a constant reference
This is a theoretical question me and my colleagues were discussing about. I will soon try it myself but i thought its an interessting topic for a newbie.
Lets imagine there is a baseclass "VEHICLE" and derived classes like "CAR" and…

harisson
- 7
- 1
-2
votes
1 answer
When to use ref and out?
So I'm working on a really simple lab for my college class and have run into a bit of a problem. My teacher failed to thoroughly explain when you would use ref and when to use out. The assignment was change a pre-written method to use ref, then make…

Brandon
- 281
- 2
- 17
-2
votes
2 answers
How can I create a list or array of references in c#?
How can I create a list or array where each element uses the ref keyword, so that if the value changes the list will still point to the new location in memory pointed to by the original reference?
Edit: I'm trying to create many objects whose only…

Dustuu
- 77
- 2
- 8
-2
votes
5 answers
C# "as" operator and advanced conversion use in loops/functions and out/ref parameters modifiers and typeof()
I Need some clarifications about:
is/as operators
out/ref parameters modifiers
typeof
Feel free to reply only to what you know or what you want to reply and not the whole question if you don't feel like.
Yes, I'm asking clarifications about these.…

Liquid Core
- 1
- 6
- 27
- 52
-3
votes
1 answer
C# - I have a list of objects, and changing the property in one object changes the property in all of them
I'm trying to make an array of objects I created (Cat) all with random properties, but per the instructions of the assignment, I have to use a separate class (Positions) and call it with one of the Cat's properties. I know this has to do with ref…

Jack0thy
- 3
- 3
-3
votes
1 answer
c# passing class instance as null not done as ref
Seems like any C# question must be duplicate, but I could not find it.
Coding in C#:
MyClassType mt = null;
dofunction(mt);
// mt was modified in dofunction to some non null value, but comes back still null
dofunction is something like
public void…

Bob Koury
- 273
- 3
- 10