пятница, 12 ноября 2010 г.

Перегрузка операторов

Ссылка: http://sivan.22host.ru/?p=8

Неявное преобразование
public static implicit operator Int32(MyIntStruct instance)
{
  return instance.m_IntValue;
}

MyIntStringStruct myIntStringStructInstance = "Hello World";

Console.WriteLine(myIntStringStructInstance);

Явное преобразование
public static explicit operator string(MyIntStringStruct instance)
{
  return instance.m_StringValue;
}

MyIntStringStruct myIntStringStructInstance = "Hello World";
Console.WriteLine((string)myIntStringStructInstance);

Перегрузка операторов
public static MySize operator +(MySize mySizeA, MySize mySizeB)
{
  return new MySize(
    mySizeA.m_Width + mySizeB.m_Width,
    mySizeA.m_Height + mySizeB.m_Height);
}

Комментариев нет:

Отправить комментарий

Еще статьи

2leep.com