Questions tagged [out]

In c#, the out keyword causes parameters to be passed by reference from the callee to the caller. The parameter doesn't have to be assigned going into a function but must be assigned before coming out of the function.

The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. For example:

class OutExample
{
    static void Method(out int i)
    {
        i = 44;
    }
    static void Main()
    {
        int value = 2;
        Method(out value);
        // value is now 44
    }
}

Although variables passed as out arguments need not be initialized prior to being passed, the called method is required to assign a value before the method returns.

The ref and out keywords are treated differently at run-time, but they are treated the same at compile time. Therefore methods cannot be overloaded if one method takes a ref argument and the other takes an out argument.

598 questions
-3
votes
1 answer

Give out parameter on event in C#

I want to give an out parameter on event but it doesn't work like this error :Cannot use parameter out in anonyme method or lambda expression public void CallMyMethod() { //{... code here`removed...just for initialize object} int? count =…
Andry
  • 13
  • 3
-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
-3
votes
1 answer

Array Out Of Bounds Exception Cannot find

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 110 at HeapPriorityQueue.hasLeft(HeapPriorityQueue.java:168) at HeapPriorityQueue.bubbleDown(HeapPriorityQueue.java:111) at…
Athind
  • 1
-3
votes
4 answers

Print out every text file

How do I print out every text file in a particular directory with BufferedReader? Because I have a method to create file in a particular directory, and at times I want to read out every text file I've created in that directory to know what I have…
Winter Leong
  • 95
  • 1
  • 1
  • 7
-4
votes
1 answer

Reference type function argument does not retain changes after function try catch block

Code below. I completely understand reference vs value types. [correction, I do not completely understand reference vs value types.] Today I ran into something odd. I declare a datatable class var and initialize it as null. I create function:…
ILoveSQL
  • 13
  • 3
-4
votes
1 answer

Jquery create new object out of DOM

Hello Im relative new into JQuery... more used to PHP Its just really simple I think but Im too stupid and if im honest JS cracks my mind....(in OOP Ive to learn much too...) So I already found out that there arent arrays like in PHP. Ok lets…
Tuppabox
  • 3
  • 4
-4
votes
2 answers

List index out of range, Does anyone know?

I am working with file tabel.txt and I'm having trouble with this. I want to display data from forth column but I am getting error: list index out of range Can anyone help me with this f = open("tabel.txt", 'r') for line in…
-5
votes
1 answer

what is the value that is passing into the called method when "out paramater" is passed

static void Main(string[] args) { int i = 10; Program th = new Program(); Thread t2 = new Thread(() => thread2(out i)); t2.Start(); Thread t1 = new Thread(() => thread1(i)); t1.Start(); Thread.Sleep(5000); …
-5
votes
2 answers

C++: Vector subscript out of range

I keep getting the error: Vector subscript out of range . I've spend an hour trying to find out why I keep getting it , it might be something obvious but I can't see it . From the trial and error trying to find out where is the problem I managed to…
-5
votes
1 answer

c# gerneric task is completely unclear

I am confronted with a task from an old exam, and I have no idea what it is about: class Demo { satic void Main() { Func xxx = null; xxx = n => n <= 1 ? 1:n * xxx(n-1); for (int m=1; m < 6; m++) …
Julian Herbold
  • 537
  • 9
  • 20
-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
-6
votes
1 answer

C# System.Double& to System.Double

I have Type variable t with value representing reference e.g. System.Double& or System.Double[]&, ... Now I would like to create an instance of object with type System.Double or System.Double[], ... Question edit: Type t =…
charlie87
  • 23
  • 3
1 2 3
39
40