求个简单的true重载的例子 比较两个对象operator true(class1,class2){ //code;}另外主要是怎么用这个重载。谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 true又不是运算符,是运算结果-_-|| 你想重载的应该是 == 运算符,或者想重写 Equals方法 ,但这都不是重写true true到的确是一个运算符,问题是你想干什么?如果是想能够比较两个值的话,重载比较运算符如==、!=、>、<等。 我就是想用一下true的重载,true的重载该怎么写,怎么用,大家给个例子吧 ,多谢 public class MyClass { public static bool operator true(MyClass my) { if (my.test1 == true && my.test2 != true) return true; else if (my.test1 != true && my.test2 == true) return true; else return false; } public static bool operator false(MyClass my) { if (my.test1 == true && my.test2 != true) return true; else if (my.test1 != true && my.test2 == true) return true; else return false; } public bool test1; public bool test2; } class Program { public static void Main() { MyClass my=new MyClass(); my.test1 = true; my.test2 = false; if (my) Console.WriteLine("first true"); else Console.WriteLine("first false"); my.test1 = false; if (my) Console.WriteLine("second true"); else Console.WriteLine("second false"); Console.ReadKey(); } }重载这东西的意义是相当于重载了||和&& 就是象“Fortner(好想退休) ”写的。运算符的重载知道怎么写,但是true的写法和用法总也弄不懂,给的代码作为参照很好,多谢了。另外,怎么给分?hehe 动态调用WebService c# DATASET保留小数 请问:在c# winform中如果有多个定时器,都是每秒轮询数据库的不同表,并处理一些逻辑??会不会把服务器搞死? 程序点退出,退出不了了! 在使用SQL Update 中遇到的一个问题? ibatis的使用,能否指点一下? IDE突然不能编译程序了,请问如何解决? c#中线程莫名其妙stopped了!!! DataGridView和DB4o配合使用的一个问题 谁能帮忙, 我开始昏头了.. VS2005 怪问题,初始化连接竟然会异常,而且时好时坏!烦请各位大侠来帮忙 本人出学C#,求指导师傅一名!急
{
public static bool operator true(MyClass my)
{
if (my.test1 == true && my.test2 != true)
return true;
else if (my.test1 != true && my.test2 == true)
return true;
else return false;
} public static bool operator false(MyClass my)
{
if (my.test1 == true && my.test2 != true)
return true;
else if (my.test1 != true && my.test2 == true)
return true;
else return false;
} public bool test1;
public bool test2;
} class Program
{
public static void Main()
{
MyClass my=new MyClass();
my.test1 = true;
my.test2 = false;
if (my)
Console.WriteLine("first true");
else
Console.WriteLine("first false");
my.test1 = false;
if (my)
Console.WriteLine("second true");
else
Console.WriteLine("second false");
Console.ReadKey();
}
}重载这东西的意义是相当于重载了||和&&