1. output

Console.WriteLine("hello world");

2. naming convention

variable: start with lower-case, use camel-case

double thePrice = 14.95;

for the rest (class name, method name, const): start with upper-case, use camel-case

const int HomeRunRecord = ;

3. value type

similar to primitive in jave

for example: int, float, bool

4. out

The out keyword causes arguments to be passed by reference. This is like the ref keyword, except that ref requires that the variable be initialized before it is passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword.

class OutExample
{
static void Method(out int i)
{
i = ;
}
static void Main()
{
int value;
Method(out value);
// value is now 44
}
}

5. ?? operator

int a = (x ?? );

equals to

int a = (x != null? x:);

6. is (check type compatible)

static void Test(object o)
{
Class1 a; if (o is Class1)
{
Console.WriteLine("o is Class1");
a = (Class1)o;
// Do something with "a."
}
}

7. compare string

not like Java, in which == and equals are different.

for string in c#, == and Equals() are the same.

if (s1.Equals(s2)){}

equals

if (s1 == s2) {}

8. define 2d array

string[,] strs = new string[, ];

access element in 2d array

strs[, ] = "hello";

9. List

var fruits = new List<string>();
fruits.Add("apple");

10. foreach

foreach (var item in fruits)
{
Console.WriteLine(item);
}

11. dictionary

            var inventory = new Dictionary<string, double>();
inventory.Add("apples", );
if (inventory.TryGetValue("apples", out value))
{
Console.WriteLine("apple value:" + value);
}

12. encapsulation

class Fruit
{
private string name; public string Name
{
get { return name; }
set { name = value; }
} }

the second line is a method call

            var f1 = new Fruit();
f1.Name = "apple";

below is a same definition of name

public string Name { get; set; }

13. override method

        public override string ToString()
{
return base.ToString();
}

14. extend class

     class Produce
{
private string name; public Produce(string name)
{
Name = name;
}
} class Fruit : Produce
{
public Fruit(string name):
base(name)
{ }
}

15. as, is

 class A
{ }
class B : A
{ } class Program
{
static void Main(string[] args)
{
B obj = new B();
A obj2 = obj as A;
if (obj is A)
{
Console.WriteLine("obj is A");
}
Console.ReadKey();
}
}

"as" is safer than below, it return null if failed to cast

A obj2 = (A)obj;

C# basic的更多相关文章

  1. Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结

    Atitit HTTP认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结 1.1. 最广泛使用的是基本验证 ( ...

  2. Basic Tutorials of Redis(9) -First Edition RedisHelper

    After learning the basic opreation of Redis,we should take some time to summarize the usage. And I w ...

  3. Basic Tutorials of Redis(8) -Transaction

    Data play an important part in our project,how can we ensure correctness of the data and prevent the ...

  4. Basic Tutorials of Redis(7) -Publish and Subscribe

    This post is mainly about the publishment and subscription in Redis.I think you may subscribe some o ...

  5. Basic Tutorials of Redis(6) - List

    Redis's List is different from C#'s List,but similar with C#'s LinkedList.Sometimes I confuse with t ...

  6. Basic Tutorials of Redis(5) - Sorted Set

    The last post is mainly about the unsorted set,in this post I will show you the sorted set playing a ...

  7. Basic Tutorials of Redis(4) -Set

    This post will introduce you to some usages of Set in Redis.The Set is a unordered set,it means that ...

  8. Basic Tutorials of Redis(3) -Hash

    When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#? ...

  9. Basic Tutorials of Redis(2) - String

    This post is mainly about how to use the commands to handle the Strings of Redis.And I will show you ...

  10. Basic Tutorials of Redis(1) - Install And Configure Redis

    Nowaday, Redis became more and more popular , many projects use it in the cache module and the store ...

随机推荐

  1. day10-redis操作

    Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...

  2. (链接)打印相关_.NET打印小资料

    掌握.NET中的日常打印:包括各个类的参数等 http://blog.csdn.net/dzweather/article/details/10171105 设置纸张大小 PrintDocument ...

  3. RabbitMQ(六)

    集群 以两台机器为例: 10.10.43.207 10.10.244.244 分别安装好 rabbitmq,之后 1.修改集群机器 erlang 的 cookie 2.修改两台机器的 hosts 3. ...

  4. 通过JS简单实现图片缩放

    ;display: none;cursor: pointer;} #FullScreenDiv{;display: none;background-color: #919191;filter: alp ...

  5. 为tomcat动态添加jndi数据源信息

    我们在开发项目的时候,总要和数据库打交道,如何获取数据源,以什么样的方式来获取,成为了我们即简单又熟悉而且不得不注意的一个问题. 那么在这里我说三种获取数据源的常用方式: 一.通过配置文件来获取 首先 ...

  6. Struts2:国际化

    链接:[Java:国际化] src下有国际化资源文件:lan.propertieslan_zh_CN.properties 中文系统系统默认使用zh_CN文件,没有的话使用基本文件lan.proper ...

  7. Have Fun with Numbers及循环链表(约瑟夫问题)

    1. 循环链表(约瑟夫问题) https://github.com/BodhiXing/Data_Structure 2. Have Fun with Numbers https://pta.pate ...

  8. cs端调用Ajax

    private static string Descoder() { //ajax地址 string MealFilePath = "http://***/user/SetWebsite.a ...

  9. 后台使用Spring MVC 4.15 版本 通过 ajaxFileUpload plugin插件上传文件相应时引起的一个小问题,Chrome、Firefox中出现SyntaxError:unexpected token <

    html: 使用ajaxFileUpload插件做文件上传时,后台返回json格式的数据,js代码如下: 接下来,把结果错误信息打印出来: 先在网上找了下解决办法方案,stackoverflow上有说 ...

  10. SQL语言基础

    主要学习链接1 http://www.cnblogs.com/anding/p/5281558.html 搜索学习链接2 http://www.cnblogs.com/libingql/p/41342 ...