类或方法名后加<>

声明类型为泛型。

说明传递的参数为泛型,而不仅仅是一种类型。
public void aa<T>(T a)
{
Console.WriteLine(a);
}
调用时可写:
this.aa<int>(5);
this.aa(string)("aaaa");

C#变量类型后面加?是什么意思?

例如:
int? id = null;
string? name = null;
还有如:

public int?[] InsertTest(int? parentId, string name, DateTime? publishTime, decimal? price, bool? isGood, out int? minId)
    {
        // 仅为说明如何做错误处理
        if (String.IsNullOrEmpty(name))
            throw new ArgumentException("参数不能是空", "name");
 
        int? id = null;
        int? count = null;
        minId = null;
 
        Singleton<TestTableAdapter>.Instance.InsertTest(parentId, name, publishTime, price, isGood, ref id, ref count, ref minId);
        return new int?[] { id, count };
    }
更多 2
View Code

答:

单问号---用于给变量设初值的时候,给变量(int类型)赋值为null,而不是0!
双问号---用于判断并赋值,先判断当前变量是否为null,如果是就可以赋一个新值,否则跳过!

 

posted on 2015-03-13 17:09  不悔的青春  阅读(4437)  评论(0编辑  收藏  举报

导航