2009/5/5 shenghe cao <caoshenghe@gmail.com>:
> enum Color {
>
> Red, // Assigned a value of 0
>
> Green, // Assigned a value of 1
>
> Blue, // Assigned a value of 2
>
> Orange // Assigned a value of 3
>
> }
>
>
>
> When an enumerated type is compiled, the compiler automatically turns each
> symbol into a constant field of the type. For example, the compiler treats
> the Color enumeration shown previously as if you had written code similar to
> this:
>
> struct Color : System.Enum {
>
> public const Color Red = (Color) 0;
>
> public const Color Green = (Color) 1;
>
> public const Color Blue = (Color) 2;
>
> public const Color Orange = (Color) 3;
>
> }
>
> 看了这个我想我们该明白为啥不能在enum重载ToString了吧
>
>
> 2008/11/25 <ya-ping_zhang@agilent.com>
>>
>> 是的,通常情况下默认实现是够用了,但是我希望重载 ToString,或许重载不是个好主意
>>
>>
>>
>> Best Regards,
>>
>> Yaping
>>
>>
>>
>> From: shenghe cao [mailto:caoshenghe@gmail.com]
>> Sent: 2008年11月25日 16:53
>> To: ZHANG,YA-PING (A-China,ex1)
>> Cc: objectsolution@googlegroups.com; zyap.cn.dongning@blogger.com
>> Subject: Re: Recall: enum 中如何处理 ToString()
>>
>>
>>
>> 我今天刚好试验了一下enum
>> 如果将一个enum得collection加到combobox中
>> 显示的就是enum得显示值啊
>>
>> 难道你的需求是需要对ToString做什么处理?我觉得他的默认实现很多时候就够用阿
>>
>> 2008/10/24 <ya-ping_zhang@agilent.com>
>>
>> ZHANG,YA-PING (A-China,ex1) would like to recall the message, "enum 中如何处理
>> ToString()".
>>
>>
>>
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "ObjectSolution" group.
> To post to this group, send email to objectsolution@googlegroups.com
> To unsubscribe from this group, send email to
> objectsolution+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/objectsolution?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>
2009年5月4日星期一
Re: Recall: enum 中如何处理 ToString()
Re: Recall: enum 中如何处理 ToString()
enum Color {
Red, // Assigned a value of 0
Green, // Assigned a value of 1
Blue, // Assigned a value of 2
Orange // Assigned a value of 3
}
When an enumerated type is compiled, the compiler automatically turns each symbol into a constant field of the type. For example, the compiler treats the Color enumeration shown previously as if you had written code similar to this:
struct Color : System.Enum {
public const Color Red = (Color) 0;
public const Color Green = (Color) 1;
public const Color Blue = (Color) 2;
public const Color Orange = (Color) 3;
}
看了这个我想我们该明白为啥不能在enum重载ToString了吧
是的,通常情况下默认实现是够用了,但是我希望重载 ToString,或许重载不是个好主意
Best Regards,
Yaping
From: shenghe cao [mailto:caoshenghe@gmail.com]
Sent: 2008年11月25日 16:53
To: ZHANG,YA-PING (A-China,ex1)
Cc: objectsolution@googlegroups.com; zyap.cn.dongning@blogger.com
Subject: Re: Recall: enum 中如何处理 ToString()
我今天刚好试验了一下enum
如果将一个enum得collection加到combobox中
显示的就是enum得显示值啊
难道你的需求是需要对ToString做什么处理?我觉得他的默认实现很多时候就够用阿
2008/10/24 <ya-ping_zhang@agilent.com>
ZHANG,YA-PING (A-China,ex1) would like to recall the message, "enum 中如何处理 ToString()".
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "ObjectSolution" group.
To post to this group, send email to objectsolution@googlegroups.com
To unsubscribe from this group, send email to objectsolution+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/objectsolution?hl=en
-~----------~----~----~----~------~----~------~--~---
2009年1月19日星期一
Google书签
在你的浏览器中输入如下网址:
http://www.google.com/bookmarks/
不知道大家用过没有,我用了觉得很好,比如,你在codeproject上看到一篇文章,想保留链接,你就可以使用书签。具体方法如下图:
实际上,更好的方式是使用 Google Notebook,试试这个 http://www.google.com/notebook/
2008年11月6日星期四
Refactor in C#
1, VS2008 itself provides:
2, A FREE tool, CodeRushX
2008年10月31日星期五
PDC2008
The Future of C#
Microsoft Visual C++: 10 Is the New 6
Framework Design Guidlines
to be continued ...
2008年9月27日星期六
C# 中的 ?? 操作符有什么用?
场景介绍:
程序存储一些用户设定到一个文件中,这些设置被分为多个集合,分别包装成class,每个集合中的值项被定义为property。如果取property为null,则可以认为文件中不存在该值得记录。
示例代码:
public class MySettings
{
public string NumOfPoints{ get; set; }
}
public class UserPreferences
{
public MySettings Settings{ get; set; }
}
class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();
string num = option.MySettings01 ?? 10; // only ONE line
}
}
class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();
// THREE lines!
string num = 10;
if( option.MySettings01 != null )
num = option.MySettings01.NumOfPoints;
}
}
总结:
C#中的操作符 ?? 在处理 property 为 null 时可以简化代码。