Questions tagged [ref]

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.

1394 questions
-3
votes
2 answers

Const reference in getter method

Can you please review this code. I believe there is nothing wrong here. You may esp. like to look the dequeue function of a class where template is used. void enqueue(const T &data) { _mutex.lock(); _queue.push(data); …
Faisal
  • 35
  • 1
-3
votes
1 answer

Pointer reset once method called second time

Can someone explain why the head and tail is reset to null once second IsAMatch is call even though id pass new pointers to it, the old ones get reset. I have equivalent script on c++ and it works perfectly. Any ideas ? my code small code example…
IronHide
  • 327
  • 1
  • 3
  • 17
-3
votes
2 answers

How to move two enumerators simultaneously?

I have two big arrays of two readonly structs: A and B. I need to enumerate over them but I need to do it in the most optimized way. readonly struct A { long a; long b; long c; long d; long e; long g; } readonly struct B { …
Dobby007
  • 1,229
  • 1
  • 12
  • 22
-3
votes
1 answer

Method Parameters with ref not working

I am trying to catch an Exception and pass those values to another method but I am getting Argument '1' must be passed with 'ref' keyword, A ref or out argument must be an assignable variable and the best overloaded method match for…
CodeMan
  • 133
  • 3
  • 19
-3
votes
1 answer

Invalid token 'ref' in class member declaration

I would like to have a reference to a byte as a class member, but it shows me an error invalid token 'ref' in class member declaration any workaround? class MCP { public byte olRegister; }; class IO { byte --reference to olRegister--; };
Quest
  • 2,764
  • 1
  • 22
  • 44
-3
votes
3 answers

Should value or reference be used, when both work the same?

If you have a method, one that takes in a variable, and doesn't actually modify the physical variable at all, should you use ref to reference the input parameter? It shouldn't really matter, because the variable isn't modified anyway, so what are…
-3
votes
4 answers

why both out & ref?

out variable references can be initialised with the address of an unassigned variable but ref variables can't do that, making out better than ref. Then what is the need for ref?
Shamseer K
  • 4,964
  • 2
  • 25
  • 43
-4
votes
1 answer

Modifying an array through a ref to one of its elements - Will it work?

It is safe to modify value types in an array through a method which uses a ref to the element in the array, as shown below? If so, what kinds of value types can be modified this way? Is it limited to simple value types or will struct also work? //…
steve
  • 21
  • 1
  • 3
-5
votes
1 answer

Does c#'s ref copy and how to prevent it?

In c++ passing a const reference is often used to save time copying. I know that c# has a ref keyword, but the accepted answer in How do I pass a const reference in C#? says that it still creates a copy of the passed variable, but modifies them…
-5
votes
1 answer

Focus issues with react

Focus is not working on the input when "isFocussed" is true componentWillReceiveProps(nextProps){ if(nextProps.isFocussed){ this.myRef.current.focus(); } }
FE_Addict
  • 647
  • 2
  • 11
  • 21
-5
votes
1 answer

why delegate work as ref?

I have program public delegate T Transformer(T arg); public class Util { public static void Transform(T[] values, Transformer t) { for (int i = 0; i < values.Length; i++) values[i] =…
streamc
  • 676
  • 3
  • 11
  • 27
-6
votes
1 answer

Memory allocation for 'Ref' and 'Out' parameter, any difference?

In C#, ref and out keyword. How to it affect memory management? Is there any difference in memory management for ref and out keyword?
Sujeet Singh
  • 165
  • 3
  • 13
-6
votes
1 answer

Partial Methods in C# and parameters

Ref and out can change the behavior of function parameters. Sometimes we want the actual value of a variable to be copied as the parameter. Other times we want a reference. These modifiers affect definite assignment analysis. My question is: can…
Tony
  • 1,177
  • 6
  • 18
  • 31
1 2 3
92
93