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
-1
votes
1 answer

How to pass any anonymous function to ref and use that in other react component?

I have 3 functional components and I'd like to pass & manipulate data through useRef. I am adding this onClose method to current property in one of my component. const onClose = () => { setButtonColor(buttonColor); }; ref.current = { …
Chandler Bing
  • 410
  • 5
  • 25
-1
votes
1 answer

How to get value in the current method from external void async method in C#?

I have method e.g. public async Task AddUser() { //some logic await _externalClass.DoSomething(); //some logic } And I want to get value from method await _externalClass.DoSomething(); (return type is Task and return type cannot be…
dimitri
  • 109
  • 6
-1
votes
1 answer

Giving a local method a referenced argument

I am passing a ref var to a method, and within the method I have a local method I'd like to ref the var that I passed to the initial method. Example below private void SomeMethod(ref var refdVar, var someThing) { //do something //then call…
maxkcy
  • 1
  • 2
-1
votes
2 answers

Passing a C# Dictionary as a function parameter to allocate its memory does not work

I have below code using System; using System.Collections.Generic; class Program { static void add(Dictionary hello){ hello = new Dictionary(); hello["hello"] = "hello"; } static void…
Pulkit Sharma
  • 390
  • 2
  • 14
-1
votes
1 answer

C# ref weird behaviour

I recently had a strange experience with C# refs. Please take a look at this code: class Program { public static bool testBool = true; public static RefClass RefObject; public static int X = 0; static void Main(string[] args) { …
Papouc
  • 25
  • 7
-1
votes
3 answers

Pass reference array as argument in c#

dears , i had create a method that will retrieve three arrays after filling them using the ref option the following error is presented "System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'" the code as below. how I can fix…
Osama
  • 1
  • 1
-1
votes
1 answer

React: problem calling child function in parent component

I made a games page in react. When you win one, it displays a form dialog (with material-UI: https://material-ui.com/components/dialogs/#form-dialogs). Component's visibility depends on the open attribute, which is changed with "handleClickOpen"…
-1
votes
2 answers

How to access the current value of dom element in react?

iam using an external library which is updating the value of input element.So in my react code there is no value and onChange handler for that input element.Now the problem is that i want to access the latest value updated by ther external libarary…
Paras Buda
  • 51
  • 1
  • 6
-1
votes
1 answer

how can ref multi type same time in c#

I created a master class to be inherited In the rest of the classes Added update alert method and at the same time set value for the property variable The problem is that I have to add a method for each type Is there a way to send the…
-1
votes
3 answers

Assign a variadic array of strings by reference in C#

I have a class called Category that takes a variadic constructor. The arguments are strings. class Category { string[] definedSets; // Sets supplied to the constructor public Category(params string[] specifiedSets) { …
Charles
  • 479
  • 1
  • 3
  • 13
-1
votes
1 answer

What happens when you change property parameter in a method without ref (C#)

I am working with some Legacy code. I general method that I usually would call like this: Poco = MyMethod(Poco.Id) // Lookup PocoToReturn on Poco.Id and return PocoToReturn are called in my Legacy like this: MyLegacyMethod(Poco) // Lookup…
-1
votes
1 answer

Im getting this error "TypeError: Cannot destructure property 'handleShow' of 'object null' as it is null." Kindly Help me with this

TypeError: Cannot destructure property 'handleShow' of 'object null' as it is null.This error comes everytime but when i refresh everything works properly for some time i tried removing handle show and added replaced it with obj and inside i added…
-1
votes
3 answers

Assign value of a reference property to a variable

I have a scenario where I want to pass in a reference of the value type bool (value type marked with ref) to a constructor of an other class and want to update its value in the other class. Something like this. Is there a way to hold the reference…
nikhil
  • 1,578
  • 3
  • 23
  • 52
-1
votes
1 answer

Losing my mind - VBA function in excell cell, unexplained #ref

It's not that I don't know WHAT exactly is going wrong but it's the not knowing WHY it's going wrong thats making me lose my mind. When writing any function in VBA with a name that has less than 4 characters and ends with a number, eq: public…
C-M
  • 201
  • 2
  • 4
-1
votes
1 answer

C# reference issue in another form

I have a small issue I wanted to clear in my head. I have a integer that I increment every second. I pass this integer as a reference to another form and want to display it. So through a button click I instanciate the second form and point the…
Nicola
  • 91
  • 8