1

i have the following global variables

private static Queue<List<object>> webdata1Queue = new Queue<List<object>>();
private static Queue<List<object>> webdata2Queue = new Queue<List<object>>();
public static DataTable products1;
public static DataTable products2;

and this function

private void Downloader(Queue<List<object>> webdataQueue,Datatable products)
        {
        }

is this the right way to pass static variables to a function? i need to pass the declared variables because i will be using the same function with 2 different threads.

7
  • 1
    yes , but if you have critical section than protect it Commented Mar 11, 2013 at 6:17
  • @Saurabh but i mean when i pass it like this, does it get passed by its adress in the memory, or another copy of the variable is made in someother place? Commented Mar 11, 2013 at 6:18
  • 2
    all objects are passed by reference in c# Commented Mar 11, 2013 at 6:19
  • 1
    @fenix2222, object's address is passed by value, Not really pass by reference, since you can't assign null to the object in a method. See Parameter passing in C# by Jon Skeet Commented Mar 11, 2013 at 6:24
  • its just that i wat to treat them as global variables without having to write the function twice!, so which one of you is right?!by default ref or value?! Commented Mar 11, 2013 at 6:27

1 Answer 1

1

If you are going to assign null to that variable or initialize it inside method then it wont work, but you can pass it like you are doing if you are just modifying properties of it and adding items to list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.