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. 学习indy组件之一idhttp的使用方法

    登录 注册 百度首页 新闻 网页 贴吧 知道 音乐 图片 视频 地图 百科 文库 经验 搜索答案我要提问 首页 分类 公社 知道行家 问医生 高质量问答 经验 个人中心手机知道开放平台   关于del ...

  2. 针对“Can't download driver to specified address”错误

    当用h-flasher检测flash-id时,可能会出现上述错误,个人认为当提示这个错误时,一般来说是sdram出现了问题,可以看看sdram有没有虚焊,或者周围的电阻电容是否正确. 在后来调板子的过 ...

  3. Android 自定义表格显示数据

    Android 自定义TextView控件,用来组成表格方便数据的展示. 首先看一下效果 样式不是很好看,需要用的可以自己优化一下. 实现方式很简单. 1.自定义控件 MyTableTextView ...

  4. js实现表单验证 常用JS表单验证

    CSS代码 @charset "gb2312"; /* CSS Document */ body,dl,dt,dd,div,form {padding:;margin:;} #he ...

  5. Cordova 打包 Android release app 过程详解

    Cordova 打包 Android release app 过程详解 时间 -- :: SegmentFault 原文 https://segmentfault.com/a/119000000517 ...

  6. 面试iOS遇到这种笔试《操作评估》

    一.开发团队需求: 开发一款软件需要前端后台和推广的人.1,首先要明确设计这个APP的理念2,合理的列出APP的需求3,找到后台人员让他们搭好后台数据4,前端的人负责展示到界面上5,推广人员负责让更多 ...

  7. 编译FFmpeg成一个SO库<转>

    转帖地址:http://www.ihubin.com/blog/android-ffmpeg-demo-3/ ============================================= ...

  8. BAT 快速删除CVS文件和拷贝最近修改文件的目录结构

    相信大家在操作大量文件的的时候,经常会遇到一些手动很难操作的情况 比如有CVS版本控制下每个文件夹下都有一个CVS文件夹,一个个手工删除肯定很费劲,我们都是懒人,还是用工具解决吧.不用重新写程序,直接 ...

  9. 正则化方法:L1和L2 regularization、数据集扩增、dropout

    正则化方法:防止过拟合,提高泛化能力 在训练数据不够多时,或者overtraining时,常常会导致overfitting(过拟合).其直观的表现如下图所示,随着训练过程的进行,模型复杂度增加,在tr ...

  10. MVC开发基础

    新建--项目--ASP.NET MVC 4 WEB 应用程序 MVC: M--Model  模型层     放置数据访问类,linq V--View  视图层       界面层   aspx文件.只 ...