• C# 3.0 的自动属性(Automatic Properties)

    香水坏坏 发表于2007-9-17 [ASP.NET]
    C#代码
    1. class Program   
    2. {   
    3.     static void Main(string[] args)   
    4.     {   
    5.         Test1 a = new Test1();   
    6.         //incorrectness   
    7.         //we would catch this exception    
    8.         //"The property or indexer 'ConsoleApplication1.Test1.PropertyB' cannot be used in this context because the set accessor is inaccessible"   
    9.         //when build project   
    10.         //a.PropertyB = "b";   
    11.   
    12.         //correct   
    13.         a.PropertyA = "a";   
    14.   
    15.         //string c = a.PropertyC;   
    16.     }   
    17. }   
    18.   
    19. //c# 3.0+   
    20. class Test1   
    21. {   
    22.     //common property type   
    23.     public string PropertyA { getset; }   
    24.     //just visiable for all other classes   
    25.     public string PropertyB { getprivate set; }    
    26.       
    27.     //this are not allowed   
    28.     //instead using a field like: string fieldC   
    29.     //public string PropertyC { private get;private set;}   
    30.   
    31.     //writable for child class and visiable for all classes;   
    32.     public string PropertyD { getprotected set; }   
    33.   
    34.     //justlin visiable for self child   
    35.     protected string PropertyE { getprivate set; }   
    36.   
    37. }   

     

    相关文章

    .net 3.0 C# 新特性http://www.aspstat.com/68

    Hits: 613  Feedback: 3  标签:C#  Trackback  Permalink: http://www.aspstat.com/89
  • 星座查询:C#版根据生日查星座

    香水坏坏 发表于2007-8-17 [ASP.NET]

    C#版根据生日求星座,算法和我之前写的JAVASCRIPT版有所不同。

     JAVASCRIPT版,查看这里:http://www.aspstat.com/30 (More...)

    Hits: 5041  Feedback: 11  标签:C# 星座  Trackback  Permalink: http://www.aspstat.com/61
  • 坏坏的分页控件

    香水坏坏 发表于2007-8-12 [ASP.NET]

    控件特性:简单、灵活、性能优越

    分页存储过程点这里

    代码如下:

    (More...)
    Hits: 710  Feedback: 4  标签:C# 分页  Trackback  Permalink: http://www.aspstat.com/54
  • 说说访问控制修饰词

    香水坏坏 发表于2007-8-11 [ASP.NET]

    估计有很多人用c#进行开发的时候,尽管用了public,private,protected,internal这些访问控制修饰词,但不一定能搞清楚什么时候该用什么时候不该用。

    下面是我对这次词的理解,不正确的地方还往大家体谅或给予补充。

    (More...)
    Hits: 583  Feedback: 1  标签:C#  Trackback  Permalink: http://www.aspstat.com/53
  • ubb代码转HTML

    香水坏坏 发表于2007-8-10 [ASP.NET]
    C#代码
    1. string UbbToHtml(string input)   
    2.         {   
    3.             string ret;   
    4.             ret = input.Replace("\r\n""<br/>");  //换行 
    5.             ret = ret.Replace(" ""&nbsp");//空格
    6.             //转换颜色
    7.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[COLOR=([^]]+)\]([^[]+)\[/COLOR\]""<span style=\"color:$1;\">$2</span>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    8.             //粗
    9.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[B\]([^[]+)\[/B\]""<b>$1</b>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    10.             //斜
    11.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[I\]([^[]+)\[/I\]""<i>$1</i>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    12.             //下划线
    13.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[U\]([^[]+)\[/U\]""<u>$1</u>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    14.             //居中
    15.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[CENTER\]([^[]+)\[/CENTER\]""<div align=\"center\">$1</div>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);               
    16.             //EMAIL
    17.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[EMAIL\]([^[]+)\[/EMAIL\]""<a href=\"mailto:$1\">$1</a>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    18.             //IMG
    19.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[IMG\]([^[]+)\[/IMG\]""<img src=\"$1\"/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    20.             //URL
    21.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[URL=([^]]+)\]([^[]+)\[/URL\]","<a href=\"$1\" target=\"_blank\">$2</a>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    22.             //URL
    23.             ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[URL=([^]]+)\]\[/URL\]","<a href=\"$1\" target=\"_blank\">$1</a>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);   
    24.             return ret;   
    25.         }  
    Hits: 851  Feedback: 4  标签:C#  Trackback  Permalink: http://www.aspstat.com/50
  • 求离最近发表时间的函数

    香水坏坏 发表于2007-7-7 [ASP.NET]
    C#代码
    1. public string DateStringFromNow(DateTime dt)   
    2. {   
    3. TimeSpan span = DateTime.Now - dt;   
    4. if (span.TotalDays > 60)   
    5. {   
    6. return dt.ToShortDateString();   
    7. }   
    8. else if ( span.TotalDays > 30 )   
    9. {   
    10. return "1个月前";   
    11. }   
    12. else if (span.TotalDays > 14)   
    13. {   
    14. return "2周前";   
    15. }   
    16. else if (span.TotalDays > 7)   
    17. {   
    18. return "1周前";   
    19. }   
    20. else if (span.TotalDays > 1)   
    21. {   
    22. return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));   
    23. }   
    24. else if (span.TotalHours > 1)   
    25. {   
    26. return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));   
    27. }   
    28. else if (span.TotalMinutes > 1)   
    29. {   
    30. return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));   
    31. }   
    32. else if (span.TotalSeconds >= 1)   
    33. {   
    34. return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));   
    35. }   
    36. else  
    37. {   
    38. return "1秒前";   
    39. }   
    40. }   
    41.   
    Hits: 579  Feedback: 0  标签:C#  Trackback  Permalink: http://www.aspstat.com/34
  • 代码片段:自定义模版,模版解析片段

    香水坏坏 发表于2007-7-7 [ASP.NET]

    作者: 香水坏坏

    转载请著名,谢谢!

    主要通过反射、字符串查找替换实现,可应用于电子邮件模版或者其他方面需要用用户自定义模版的地方,但又不能以PAGE形式输出等等

    (More...)
    Hits: 378  Feedback: 0  标签:C# 模版  Trackback  Permalink: http://www.aspstat.com/23
  • 数据库字段映射到类实体

    香水坏坏 发表于2007-7-7 [ASP.NET]

     

    作者: 香水坏坏

    转载请著名,谢谢!

     

    C#代码
    1. using System;       
    2. using System.Data;       
    3. using System.Collections.Generic;       
    4. using System.Text;       
    5. using System.Reflection;     
    (More...)
    Hits: 463  Feedback: 0  标签:C# 数据库  Trackback  Permalink: http://www.aspstat.com/22