siddharth rai

siddharth rai

  • NA
  • 10
  • 3.8k

operator overloading

Jul 24 2012 8:19 AM

please explain that program.why how compile move and what is the reason that in overriden function "ToString"  the statement within Console.WriteLine("ToString " ) is not exicuted.


a.cs

public class zzz

{

public static void Main()

{

yyy a = new yyy(10);

System.Console.WriteLine(a);

}

}

public class yyy

{

public int i;

public yyy( int j)

{

i = j;

}

public static implicit operator string(yyy y)

{

System.Console.WriteLine("operator string");

return "string " + y.i;

}

public override string ToString()

{

System.Console.WriteLine("ToString");

return "mukhi";

}

}

 

Output

operator string

string 10


Answers (3)