J
Jay Dee
Hi all,
I am slightly confused about an odd result that douse not create an
error, but also douse not give the result I would expect.
My aim was to output data to a text file.
If the data was passed by value, output the name and the data.
If the data was by ref to output just the name as reference to the
data because the data has already bean output previously in the file.
As an example, this code should accept a string by value or ref and
output true or false depending on witch.
// CODE
class TestClass
{
public void Test(string Obj)
{
System.Type Type = Obj.GetType();
if (Type.IsByRef == true)
{ System.Windows.Forms.MessageBox.Show("True"); }
else { System.Windows.Forms.MessageBox.Show("False"); }
}
public void Test(ref string Obj)
{
System.Type Type = Obj.GetType();
if (Type.IsByRef == true)
{ System.Windows.Forms.MessageBox.Show("True"); }
else { System.Windows.Forms.MessageBox.Show("False"); }
}
}
// END
When called with a value then a ref, e.g.
// CODE
string theString = "Data";
TestClass TestClass = new TestClass();
TestClass.Test(theString);
TestClass.Test(ref theString);
// END
I world expect it to display "False" then "True".
However called "false" is always output and I can not understand why.
Am I using the wrong approach or doing something else wrong.
Thank you in advance for any suggestions.
I am slightly confused about an odd result that douse not create an
error, but also douse not give the result I would expect.
My aim was to output data to a text file.
If the data was passed by value, output the name and the data.
If the data was by ref to output just the name as reference to the
data because the data has already bean output previously in the file.
As an example, this code should accept a string by value or ref and
output true or false depending on witch.
// CODE
class TestClass
{
public void Test(string Obj)
{
System.Type Type = Obj.GetType();
if (Type.IsByRef == true)
{ System.Windows.Forms.MessageBox.Show("True"); }
else { System.Windows.Forms.MessageBox.Show("False"); }
}
public void Test(ref string Obj)
{
System.Type Type = Obj.GetType();
if (Type.IsByRef == true)
{ System.Windows.Forms.MessageBox.Show("True"); }
else { System.Windows.Forms.MessageBox.Show("False"); }
}
}
// END
When called with a value then a ref, e.g.
// CODE
string theString = "Data";
TestClass TestClass = new TestClass();
TestClass.Test(theString);
TestClass.Test(ref theString);
// END
I world expect it to display "False" then "True".
However called "false" is always output and I can not understand why.
Am I using the wrong approach or doing something else wrong.
Thank you in advance for any suggestions.