Test If Out Parameter has been assigned
-
I thought I understood how Out worked until I found out that you could pass a value through to the function with it. In other words the out parameter can be assigned before the function call. The compiler insists that the parameter is assigned before return even though it could have been assigned prior to the function call. I suspect the answer is no - but is there any way to test if the parameter is assigned and if so get it's value. This would be useful.
-
I thought I understood how Out worked until I found out that you could pass a value through to the function with it. In other words the out parameter can be assigned before the function call. The compiler insists that the parameter is assigned before return even though it could have been assigned prior to the function call. I suspect the answer is no - but is there any way to test if the parameter is assigned and if so get it's value. This would be useful.
If you declare your method with an
out
parameter you are stating that the method will set that parameter, no matter whether the parameter was already set or not. " Although variables passed as out arguments do not have to be initialized before being passed, the called method is required to assign a value before the method returns. " Could you please tell us more about what you are trying to do? -
I thought I understood how Out worked until I found out that you could pass a value through to the function with it. In other words the out parameter can be assigned before the function call. The compiler insists that the parameter is assigned before return even though it could have been assigned prior to the function call. I suspect the answer is no - but is there any way to test if the parameter is assigned and if so get it's value. This would be useful.
-
I thought I understood how Out worked until I found out that you could pass a value through to the function with it. In other words the out parameter can be assigned before the function call. The compiler insists that the parameter is assigned before return even though it could have been assigned prior to the function call. I suspect the answer is no - but is there any way to test if the parameter is assigned and if so get it's value. This would be useful.
Even if you pass the out parameter with a value it will need to be assigned a value in the function before being accessed, but if you feel like you want to assign it a value before rather use ref not out.
"I cannot confirm my earlier denial and I cannot deny my earlier confirmation and DON'T QUOTE ME ON THAT"
-
Even if you pass the out parameter with a value it will need to be assigned a value in the function before being accessed, but if you feel like you want to assign it a value before rather use ref not out.
"I cannot confirm my earlier denial and I cannot deny my earlier confirmation and DON'T QUOTE ME ON THAT"
Yeah, I suppose I wanted to have the option of either assigning the parameter before the function call or within it. I hoped this would have worked... private void SomeFunc(out string TStr) { if(TStr == null) TStr = ""; } But of course it doesn't. No worries ... I'll just use ref ... Thanks anyway.