-
C# 3.0 的自动属性(Automatic Properties)
香水坏坏 发表于2007-9-17 [ASP.NET]C#代码- class Program
- {
- static void Main(string[] args)
- {
- Test1 a = new Test1();
- //incorrectness
- //we would catch this exception
- //"The property or indexer 'ConsoleApplication1.Test1.PropertyB' cannot be used in this context because the set accessor is inaccessible"
- //when build project
- //a.PropertyB = "b";
- //correct
- a.PropertyA = "a";
- //string c = a.PropertyC;
- }
- }
- //c# 3.0+
- class Test1
- {
- //common property type
- public string PropertyA { get; set; }
- //just visiable for all other classes
- public string PropertyB { get; private set; }
- //this are not allowed
- //instead using a field like: string fieldC
- //public string PropertyC { private get;private set;}
- //writable for child class and visiable for all classes;
- public string PropertyD { get; protected set; }
- //justlin visiable for self child
- protected string PropertyE { get; private set; }
- }
相关文章
.net 3.0 C# 新特性http://www.aspstat.com/68
-
星座查询:C#版根据生日查星座
香水坏坏 发表于2007-8-17 [ASP.NET]C#版根据生日求星座,算法和我之前写的JAVASCRIPT版有所不同。
JAVASCRIPT版,查看这里:http://www.aspstat.com/30 (More...)
-
坏坏的分页控件
香水坏坏 发表于2007-8-12 [ASP.NET] -
说说访问控制修饰词
香水坏坏 发表于2007-8-11 [ASP.NET]估计有很多人用c#进行开发的时候,尽管用了public,private,protected,internal这些访问控制修饰词,但不一定能搞清楚什么时候该用什么时候不该用。
下面是我对这次词的理解,不正确的地方还往大家体谅或给予补充。
(More...) -
ubb代码转HTML
香水坏坏 发表于2007-8-10 [ASP.NET]C#代码- string UbbToHtml(string input)
- {
- string ret;
- ret = input.Replace("\r\n", "<br/>"); //换行
- ret = ret.Replace(" ", " ");//空格
- //转换颜色
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[COLOR=([^]]+)\]([^[]+)\[/COLOR\]", "<span style=\"color:$1;\">$2</span>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //粗
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[B\]([^[]+)\[/B\]", "<b>$1</b>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //斜
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[I\]([^[]+)\[/I\]", "<i>$1</i>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //下划线
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[U\]([^[]+)\[/U\]", "<u>$1</u>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //居中
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[CENTER\]([^[]+)\[/CENTER\]", "<div align=\"center\">$1</div>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[EMAIL\]([^[]+)\[/EMAIL\]", "<a href=\"mailto:$1\">$1</a>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //IMG
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[IMG\]([^[]+)\[/IMG\]", "<img src=\"$1\"/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //URL
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[URL=([^]]+)\]([^[]+)\[/URL\]","<a href=\"$1\" target=\"_blank\">$2</a>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- //URL
- ret = System.Text.RegularExpressions.Regex.Replace(ret, @"\[URL=([^]]+)\]\[/URL\]","<a href=\"$1\" target=\"_blank\">$1</a>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- return ret;
- }
-
求离最近发表时间的函数
香水坏坏 发表于2007-7-7 [ASP.NET]C#代码- public string DateStringFromNow(DateTime dt)
- {
- TimeSpan span = DateTime.Now - dt;
- if (span.TotalDays > 60)
- {
- return dt.ToShortDateString();
- }
- else if ( span.TotalDays > 30 )
- {
- return "1个月前";
- }
- else if (span.TotalDays > 14)
- {
- return "2周前";
- }
- else if (span.TotalDays > 7)
- {
- return "1周前";
- }
- else if (span.TotalDays > 1)
- {
- return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
- }
- else if (span.TotalHours > 1)
- {
- return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
- }
- else if (span.TotalMinutes > 1)
- {
- return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
- }
- else if (span.TotalSeconds >= 1)
- {
- return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
- }
- else
- {
- return "1秒前";
- }
- }
-
代码片段:自定义模版,模版解析片段
香水坏坏 发表于2007-7-7 [ASP.NET] -
数据库字段映射到类实体
香水坏坏 发表于2007-7-7 [ASP.NET]作者: 香水坏坏
转载请著名,谢谢!
(More...)C#代码- using System;
- using System.Data;
- using System.Collections.Generic;
- using System.Text;
- using System.Reflection;

