https://blog.csdn.net/easyjf/article/details/2293172
最近因工作需要参与了一个.Net小 项目,语言使用C#,虽然这语言很多地方来源于Java,然而搞Java久了来搞C#还真有一点不习惯,其中一个最不习惯的是C#中的属性首字母大小。比如:
public
class
Topic
{
private Long id;
private String title;
private String content;
private String intro;
private TopicCategory category;
private List<TopicComment> comments = new java.util.ArrayList<TopicComment>();
private Date inputTime = new Date();
private Integer readTimes = 0;
//然后下面是getter及setter方法
}
private Long id;
private String title;
private String content;
private String intro;
private TopicCategory category;
private List<TopicComment> comments = new java.util.ArrayList<TopicComment>();
private Date inputTime = new Date();
private Integer readTimes = 0;
//然后下面是getter及setter方法
}
而C#的版本
public
class
Topic
{
private long id;
private string title;
private string content;
private string intro;
private TopicCategory category;
private IList<TopicComment> comments = new List<TopicComment>();
private DateTime inputTime = DateTime.Now;
private int readTimes = 0;
public virtual long Id
{
get { return id; }
set { id = value; }
}
public virtual string Title
{
get { return title; }
set { title = value; }
}
public virtual string Content
{
get { return content; }
set { content = value; }
}
public virtual string Intro
{
get { return intro; }
set { intro = value; }
}
public virtual TopicCategory Category
{
get { return category; }
set { category = value; }
}
public virtual IList<TopicComment> Comments
{
get { return comments; }
set { comments = value; }
}
public virtual DateTime InputTime
{
get { return inputTime; }
set { inputTime = value; }
}
public virtual int ReadTimes
{
get { return readTimes; }
set { readTimes = value; }
}
}
{
private long id;
private string title;
private string content;
private string intro;
private TopicCategory category;
private IList<TopicComment> comments = new List<TopicComment>();
private DateTime inputTime = DateTime.Now;
private int readTimes = 0;
public virtual long Id
{
get { return id; }
set { id = value; }
}
public virtual string Title
{
get { return title; }
set { title = value; }
}
public virtual string Content
{
get { return content; }
set { content = value; }
}
public virtual string Intro
{
get { return intro; }
set { intro = value; }
}
public virtual TopicCategory Category
{
get { return category; }
set { category = value; }
}
public virtual IList<TopicComment> Comments
{
get { return comments; }
set { comments = value; }
}
public virtual DateTime InputTime
{
get { return inputTime; }
set { inputTime = value; }
}
public virtual int ReadTimes
{
get { return readTimes; }
set { readTimes = value; }
}
}
在表示层中直接使用Topic对象的属性,用java的话直接写成topic.title、topic.category等,而用C#则属性默认为Pascal,全部必须写为topic.Title、topic.Category等。由于该系统是一个Ajax应用,因此可想而知如果是做移植的话,客户端要移植多少的代码才行。而且我发现像JavaScript、Php及其它动态语言这些的属性推荐的也是使用Camel–Pascal,即与java一样。语言用多了,有点感觉.Net是在故意搞自己的一套啊,有点不遵守大小的规矩。
比如C#中的bool类型,当输出成字符串的时候,布尔真默认输出为True,也是首字母大小。而我们知道javascript中的布尔常量为true,由于大小写是有区别的,写成True则问题就严重了。如果要把一个对象转换成JSON,你还得想办法让bool值首字母小写,很麻烦啊。
发现.Net一直在吸引整合其它平台的设计思想、理念乃至产品等,然而如果什么都搞一套自己的,这样在以后会不会是大问题呢?