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. 第二周:If判断语句程序当中的作用简介

    1.If语句的作用: 在我们编写程序时经常会遇到内容判断的问题,比如判断内容的真假或者值的大小分别输出内容的问题 这时就会用到我们的If判断语句了,顾名思义,if在英文单词中意思为如果,在Java中他 ...

  2. 【HOW】如何手工编辑InfoPath文件

    因为直接打开InfoPath的配置文件进行编辑会有些无从下手,所以下面以修改“节”的Margin为例来说明手工编辑InfoPath文件的过程. 1. 新建一个“节”,并在此节中创建一个数字类型字段“n ...

  3. 02-C#入门(循环)

    记得第一次学编程的时候,就听说过一句话:“新手学习和掌握一门编程语言是很容易的,但是如果你学会了某种编程语言,再去学习新的语言,就很难掌握了”,现在深深地感受到了这方面的阻力. 其实流程控制.循环,包 ...

  4. Unity5中的MetaPass

    前些天烘焙lightmap的时候发现用自己写的Shader的模型在烘焙时候不会烘焙效果不对,它不会产生对周围物体的间接光照,但是我放到了unity4.x中就是没问题的.查了一番,发现Unity5中加了 ...

  5. Map小结

    Map主要用于存储健值对个人理解:因为Map是根据键得到值,因此需要保证键值的唯一性,不允许键重复(重复了覆盖了),但允许值重复.1.HashMap根据键的HashCode 值存储数据,根据键可以直接 ...

  6. (Hibernate进阶)Hibernate映射——一对多关联映射(七)

    一对多关联映射 映射原理 一对多关联映射和多对一关联映射的映射原理是一致的,都是在多的一端加入一个外键,指向一的一端.关联关系都是由多端维护,只是在写映射时发生了变化. 多对一和一对多的区别 多对一和 ...

  7. 施耐德Sepam 40系列备自投逻辑

    1# 主供: VL1= NOT PVTS_1_3 V1 = VL1 AND P59_1_7 AND P59_1_8 AND P59_1_9VL2 = VL1 AND I12 AND I21 AND I ...

  8. oracle DBlink 【转】

    . 实现结果:在一个数据库中某个用户下编写一个存储过程,在存储过程中使用DBLINK连接另一个数据库,从此数据库中的一个用户下取数,然后插入当前的数据库中的一个表中. 二. 实现方法步骤: 1. 创建 ...

  9. 在requirejs中使用qunit

    requirejs(['QUnit'], function(qunit) { qunit.test('test name', function(assert) { // 一些测试, assert }) ...

  10. Shaders(读书笔记4 --- Real-Time rendering)

    1. vertex,pixel以及geometry shaders共享一个programming model,即common-shader core,在GPU架构中的unified shader可以和 ...