Passing Autumn

The same 3 years, and some people from students to as the MVP, and I was in place, then the code to show off the autumn wind, a little sad, a little cool!

Bulletin
Content is very powerful ~ ~ ~ ~ ~ ~ Do not look outside the invasion not as sharp and brother, I felt kind of sense of loss ~ ~ ~

C#与Java对比学习:类型判断、类与接口继承、代码规范与编码习惯、常量定义

类型判断符号:

  C#:object a;  if(a is int) { }  用 is 符号判断

Java:object a; if(a instanceof Integer) { } 用 instanceof 符号判断

 

类与接口的继承:

   C#:public class MDataRow : List<MDataCell>, IDataRecord, ICustomTypeDescriptor

Java:public class MDataRow extends ArrayList<MDataCell> implements Set


共同点都是在顺序上,先基类,后接口。 

C#的继承与实现,先用":"打头,再用“,“分隔,其中接口都规范用 I 开头。

Java的类继承用extends,接口实现用implements,接口没有“I”开头规范,容易傻傻分不清是类还是接口。


代码规范与编码习惯:

看一小段Java代码:

package Test;
import java.lang.*;

public class Demo {
    int id;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public Demo(int id) {
        super();
        this.id = id;
    }
    
    void write(){
        System.out.print(id);
    }
}

基本比较如下:  

  C#:namespace ; using   ; 方法首字母大写 ; base  调用基类相关成员 ; 默认括号是换行
Java:package     ; import ; 方法首字母小写 ; super 调用基类相关成员 ; 默认括号无换行

 

C#多出来的一些属性与语法: 

由于C#是鉴习Java之后产生的语言,所以C#会比Java多一些东西,这些是有和无的关系,只顺路一提了:

属性、枚举、委托、事件、unsafe(代码指针)、重载复盖方法相关的操作符(override、virtual、new)、引用传参(ref、out)、字符转义(@)等。

 

常量定义:


  C#:const string name; 或 static readonly string name;

 Java:final string name;

 

 今天事比较多,就到这了。

Autumn Park is QBlog the official site, created by the passing autumn, based on the framework data layers developed cyqdata support multi-user, multi-language, multi-database (access, mssql, oracle), directory level url and other powerful blog system
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2013/7/31 2:07:08 | Other | |

#1游客[注册][171.107.29.*]2013/8/14 0:53:11
曾经想买本书,《从C#到Java》,结果发现只有《从Java到C#》。学一门语言是容易的,难在于类库的重新学习、常用技巧等。

路过秋天 加油,你写好后我再来学。。。
  • Post Comment