M
Mark Oliver
Hi, I want to put a type conversion in my class, but I don't want the
conversion to be usable in a passed parameter because it makes no sense.
class cData
{
string s;
public cData(string s)
{
this.s=s;
}
public static implicit operator cData(string s)
{
cData data=new cData(null);
data.s=s;
return data;
}
public void f(cData data)
{
data.s=s;
}
} // class cData
void test()
{
string s="123";
cData data1=new cData("456");
data1=s; // this is OK, it's why I want the type conversion, data1
changes to a new cData with s="123"
// but I don't want this
data1.f(s); // C# passes reference types by reference - no type
converted parameters should be allowed
// it should be a compiler error - IT DOES NOTHING
cData data2=new cData("789");
data1.f(data2); // this is OK, it's why I want the function f, data2.s
changes to "456"
}
conversion to be usable in a passed parameter because it makes no sense.
class cData
{
string s;
public cData(string s)
{
this.s=s;
}
public static implicit operator cData(string s)
{
cData data=new cData(null);
data.s=s;
return data;
}
public void f(cData data)
{
data.s=s;
}
} // class cData
void test()
{
string s="123";
cData data1=new cData("456");
data1=s; // this is OK, it's why I want the type conversion, data1
changes to a new cData with s="123"
// but I don't want this
data1.f(s); // C# passes reference types by reference - no type
converted parameters should be allowed
// it should be a compiler error - IT DOES NOTHING
cData data2=new cData("789");
data1.f(data2); // this is OK, it's why I want the function f, data2.s
changes to "456"
}