2009年5月4日星期一

Re: Recall: enum 中如何处理 ToString()

和C++一样。不过 C# 很 rich,如果编译器想做,还是可以做得到的。meta data目前包含了 class 的信息。包含一些 enum 的还是可行的。

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
> -~----------~----~----~----~------~----~------~--~---
>
>

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了吧




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年1月19日星期一

Google书签

在你的浏览器中输入如下网址:

http://www.google.com/bookmarks/

不知道大家用过没有,我用了觉得很好,比如,你在codeproject上看到一篇文章,想保留链接,你就可以使用书签。具体方法如下图:



这样,你就可以把这个网页保存在你的书签中了,如下图:














实际上,更好的方式是使用 Google Notebook,试试这个 http://www.google.com/notebook/

2008年11月6日星期四

Refactor in C#

I am loving the productivity enhancements by using Refactor in VS2008.

1, VS2008 itself provides:


2, A FREE tool, CodeRushX



2008年10月31日星期五

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 时可以简化代码。

2008年9月23日星期二

使用Google阅读器,共享你看到的好文章

Google Reader有个功能,就是能向你的Google好友共享你看到的好文章