C# 创建自定义转换
来源:互联网 发布:cf抽奖算法 编辑:程序博客网 时间:2024/05/28 05:18
public class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public Rectangle() { }
public Rectangle(int w,int h)
{
this.Width = w;
this.Height = h;
}
public void Draw()
{
for (int i = 0; i < Height;i++ )
{
for (int j = 0; j < Width; j++)
{
System.Console.Write("*");
}
}
}
public override string ToString()
{
return string.Format("Width: {0},Heigth: {1}",this.Width,this.Height);
}
}
public class Square
{
public int Length { get; set; }
public Square();
public Square(int i)
{
this.Length = i;
}
public void Draw()
{
for (int m = 0; m < Length;m++ )
{
for (int n = 0; n < Length; n++)
{
System.Console.Write("*");
}
}
}
public override string ToString()
{
return string.Format("Length: {0}",this.Length);
}
/// <summary>
/// 矩形可显示转换为正方形
/// </summary>
public static explicit operator Square(Rectangle c)
{
Square s = new Square();
s.Length = c.Height;
return s;
}
}
Rectangle r = new Rectangle() { Width = 4,Height = 3 };
Square s = (Square)r;
s.Draw();
- C# 创建自定义转换
- c# 创建自定义时区
- C#中的自定义类型转换
- C#自定义类型强制转换
- C#用户自定义转换示例
- c#中自定义类转换
- 创建CLR自定义触发器-C#
- C# GDI创建自定义进度条
- FastReport 创建“人民币大小写转换”自定义函数
- C#自定义结构的强制转换
- 常用自定义C#类型转换函数
- C# 自定义 implicit和explicit转换
- C#自定义类型的强制转换
- 在C#中创建自定义控件
- 在C#中创建自定义控件
- 在C#中创建SQLite自定义函数
- 使用C#对SQLite创建自定义函数
- C#下WPF创建自定义透明窗口
- UVA 10312 - Expression Bracketing(数论+Catalan数)
- Linux find命令详解和实例说明
- contextlib——上下文管理
- 【JavaWeb】基础知识总结05 jQuery
- POJ 1003
- C# 创建自定义转换
- UVA 10497 - Sweet Child Makes Trouble(DP+高精度)
- 飞鸽传书文件记录选择CFile还是CStdioFile?
- 对.Net系统架构改造的一点经验和教训
- 屏幕录像专家 共享版 V7.5 安装图解
- 数据结构与算法分析学习笔记--第四章(搜索二叉树,递归和非递归实现删除、插入)
- WhyHTTP.html
- a+b
- 2014.5.11博客第一天