Tricky C # syntax for out function parameter

I am familiar with using a simple data type for manipulation, but I cannot figure out how to get into this Queue<> without causing a compilation error. Any ideas?

the code:

 Queue<SqlCommand> insertScriptQueue = new Queue<SqlCommand>(); private void UpdateDefaultIndicator(int newDefaultViewID, out (Queue<SqlCommand>) insertScriptQueue) UpdateDefaultIndicator(newViewID, out (Queue<SqlCommand>)insertScriptQueue); 
+4
source share
7 answers

In any case, the queue will be passed by reference, not the type of value. Just don't use 'out'. UPDATE: Forgive me, I was thinking about β€œref”, but the fact that you are passing the Queue data type to, and not just an unallocated link, makes me think that you want to use β€œref” anyway. Also, you do not need to use 'ref' because Queue is not a value type; it will already be passed by default "by reference".

+2
source

You are passing a reference type. No need to use.

+5
source

You should not initialize the out variable. If you need to change the in-scope variable, use ref instead.

As Ed points out in his comment, a β€œchange” may not give you a complete picture of what is going on here - the out parameter of the reference type will, by definition, be an initialized object at the end of the function call. As pointed out in most other answers, if you want to pass an initialized object, ref is a stronger choice.

+4
source
 Queue<SqlCommand> insertScriptQueue; private void UpdateDefaultIndicator(int newDefaultViewID, out Queue<SqlCommand> insertScriptQueue){/*body*/} UpdateDefaultIndicator(newViewID,out insertScriptQueue); 

This works great for me ... What error do you get?

+3
source

Why do you want to "exit" ... here ... why aren't you returning a type instead? Let the method return Queue <> insteasd void .. will this work for you?

+3
source

make sure you assign insertScriptQueue some value inside the UpdateDefaultIndicator method

0
source

The answer to the original question, by the way, is what you send to the queue, and the listing returns an intermediate link. This link cannot be assigned and therefore is not a legal parameter. Erich code implements a fix for this problem.

0
source

All Articles