C# (passing by reference)
don't use the ref keyword! Use the 'out' keyword instead.
When writing a method, you use ref when you want to manipulate something and
know it was initialized before the method was called. If you are going to
ignore the value of the object that was passed in, you declare the arguement
as 'out'.
Whatever way the method is declared is the way it must be called.
You may get unpredictable results if you call a method expecting a 'ref'
parameter with a variable that has a null value!
I recommend looking at the help files for the 'ref' and 'out' keywords.
Mike
Quote:
> Dears,
> i have the following Function in VB
> Private Sub GenerateSoapException(ByRef SoapExcept As SoapException, ByVal
> ErrMsg As String)
> in one other method i call it simply as the following code.
> Dim SoapEx As SoapException
> try
> .....
> Catch ex As Exception
> GenerateSoapException(SoapEx, ex.Message)
> Throw SoapEx
> .....
> NOW THAT WAS WORKING WITH VB,
> EVEN I DID NOT INSTANTIATE OBJECT SoapEx.
> now in C#
> private void GenerateSoapExcption(ref SoapException SoapExcept,string
> ErrMsg)
> try{...}
> catch(Exception e){
> GenerateSoapExcption(ref SoapEx,e.Message);
> throw SoapEx;
> }
> NOW IN THIS C# CODE IT REQUEIRS ME TO INSTANTIATE(Create an instance) of
the
> OBJECT SoapEX
> before sending it to GenerateSoapException Method.
> WHAT IS HAPPING HERE?
> CAN ANY ONE HELP.