Part 11-12 switch statement in C#

switch statement

break statement   if break statement is used inside a switch statement,he control will leave the switch statement

goto statement    you can either jump to another case statement,or to specific label(label is some word you coding to mark).

         Warning:Using goto is bad programming style,we can should avoid go to by all means

Multiple if else statements can be replaced with a switch statement

for an excample:

if(number ==10)
Console.WriteLine("you number is 10");
else if(number ==20)
Console.WriteLine("you number is 20");
else if(number ==30)
Console.WriteLine("you number is 30");
else
Console.WriteLine("you number is not 10 to 30"); above code can be replaced as: switch(number)
{
  case :10
  Console.WriteLine("you number is 10");
  break;
  case :20
  Console.WriteLine("you number is 20");
  break;
case :30
  Console.WriteLine("you number is 30");
  break;
defalut:
  Console.WriteLine("you number is not 10 to 30");
break;
} or can be replaced as: switch(number)
{
  case:10
case:20  
  case:30
  Console.WriteLine("you number is{0}",number);
break;
  default:
  Console.WriteLine("you number is not 10 to 30");
break;
}

Noted that switch(expression) , expression value must be bool , char, string, int ,enum or nullable type.

Part 13 while loop in c#

1,while loop checks the condition first.

2,if the condition is true,statements with in the loop are executed.

3,this process is repeated as long as the condition evaluetes to true.

Note:Don't forget to update the variable participating in the condition,so the loop can end , at some point

Part 14 do while loop in c#

1,a do loop checks its condition at the end of the loop.

2,this means that the do loop is guranteed to execute at least one time.

3,do loops are used to present a menu to the user

Difference -while & do while

1,while loop checks the condition at the beginning, where as do while loop checks the condition at the end of the loop.

2,do loop is guaranteed to execute at least once, where as while loop is not

Part 15 for and foreach loops in c#

The for loop

A for loop is very similar to while loop. in a while loop we do the initialization at one place, condition check at another place, and modifying the variable at another place,where as for loop has all of these at one place.

foreach loop

A foreach loop is used to iterate through the items in a collection.For example,foreach loop can be used with arrays or collectioins such as ArrayList, HashTable and Generics.

Part 16 Methods in c#

Static Vs Instance methods

static method is invoked using the class name, where are an instance method is invoked using an instance of the class.

the difference between instance methods and static methods is that multiple instances of a class can be created(or instantiated) and each instance has its own separate method. however, when a method is static,there are no instances of that method, and you can invoke only that one definition of the static method

Part 17  Method parameters

The 4 types of method parameters

1,value parameters

2,reference parameters(use ref keyword)

3,out parameters(use out keyword)

4,parameter arrays(use params keyword ,should be the last one in the parameters list,and only have one params paremeter.)

method parameters Vs method arguments

Pass by value/reference:

public static void main()
{
int i =0;
Change1(i); // 0 pass by value
Change2(ref i); // 1 pass by reference
}
public static void Change1(int j)
{
j =1;
Console.Write(j);
}
public static void Change2(ref int j)
{
j=1;
Console.Write(j);
}

Pass by value: i and j are pointing to different memory locations. Operations one valiable will not affect the value of the other variable.

Pass by reference: i and j are pointing to the same memory location. Operations one valiable will affect the value of the other variable.

Part 18 namespace

namespaces are used to organize your programs

they also provide assistance(帮助) in avoiding(避免) name clashes(冲突)

namespaces don't correspond(对应) to file, directory(目录) or assembly(程序集) names. they could be wirtten in separate(单独) files and/or separate assemblies and still belong to the same namespace.

Namespaces can be nested(嵌套) in 2 ways.

namespace alias directives(指令).  sometimes you may encounter(遇到) a long namespace and wish to have it shorter. this could improve(提高) readability(可读性) and still avoid(避免) name clashes(冲突) with similarly named methods.

if the name of namespace is to long,you can use 'name'='namespace' to improve readability.

eg:

before:  using system.subsystem.hello

after:    using ssh = system.subsystem.hello

Part 19 Introduction to classes

what is a class

a class consists of(由..组成) data and behavior. class data is represented(代表) by it's fields and behavior is represented by it's methods

Purpose of a class constructor

The purpose of a class constructor is to initialize class fields. A class constructor is automatically called when an instance(实例) of a class is created.

Constructors do not have return values and always have the same name as the class.

Constructors are not mandatory(强制性的). if we do not provide a constructor, a default parameter less constructor is automatically provided.

Constructors can be overloaded by the number and type of parameters.

Part 20 Static and instance class members

Static class members

Instance class members

Difference between static and instance members

An example explaining when you should make certain members static

Static and Instance class memebers

When a class memeber includes a static modifier, the member is called as static member.

When no static modifier is present the member is called as non static member or instance member.

Static members are invoked using class name, where as instance members are invoked using instances(object) of the class.

An instance member belongs to specific instance(object) of a class. if I create 3 objects of a class, I will have 3 sets of instance members in the memory, where as there will ever be only one copy of a static member, no matter how many instances of a class are created.

Note: Class member = field, methods, properties, events, indexers,constructor.

Static constructor

Static constructors are used to initialize static fields in a class.

you declare a static constructor by using the keyword static in front of the constructor name.

Static Constructor is called only once, on matter how many instances you create.

Static constructors are called before instance constructors.

Part 11 to 20 Basic in C# continue的更多相关文章

  1. 2016年11月20日 星期日 --出埃及记 Exodus 20:11

    2016年11月20日 星期日 --出埃及记 Exodus 20:11 For in six days the LORD made the heavens and the earth, the sea ...

  2. 2019-03-18 Python time 将2015年11月20日转换为2015-11-20

    #ReportingDate = soup.select('body > div.main > div > div.ctr > div.recruit > ul > ...

  3. tmux使用——2019年11月20日16:40:15

    1.tmux 命令行的典型使用方式是,打开一个终端窗口(terminal window,以下简称"窗口"),在里面输入命令.用户与计算机的这种临时的交互,称为一次"会话& ...

  4. Navicat for mysql 11.1.20激活

    由于最近工作太忙,一直没有机会分享自己在工作中遇到的困难,今天周日,在出去之前先分享下navicat(版本很重要navicat_trial_11.1.20.0.1449226634)激活. 刚开始我是 ...

  5. 2018年11月20日 远交近攻 list1

    list 列表用法 li=[1,2,3,"abc"] #列表中的元素,可以为数字或者字符串或者布尔值或者就是列表等,所有都能放进去 #列表中也能嵌套列表 pi=[1,2,3,[2, ...

  6. MySQL Crash Course #11# Chapter 20. Updating and Deleting Data

    INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...

  7. 2017年11月20日 WinForm窗体 窗口无边框可移动&&窗口阴影 控制窗口关闭/最小化

    弹框 MessageBox.Show(); 清空 clear() 字符串拼接 string 公共控件 button 按钮 checkbox 复选框 checklistbox 多个复选框 combobo ...

  8. 软件工程项目组Z.XML会议记录 2013/11/20

    软件工程项目组Z.XML会议记录 [例会时间]2013年11月20日星期三21:00-22:00 [例会形式]小组讨论 [例会地点]学生公寓3号楼会客厅 [例会主持]李孟 [会议记录]李孟 会议整体流 ...

  9. PYDay10&11&12&13-常用模块:time|datetime|os|sys|pickle|json|xml|shutil|logging|paramiko、configparser、字符串格式化、py自动全局变量、生成器迭代器

    1.py文件自动创建的全局变量 print(vars()) 返回值:{'__name__': '__main__', '__package__': None, '__loader__': <_f ...

随机推荐

  1. 2021“MINIEYE杯”中国大学生算法设计超级联赛(8)(1002,1004,1006,1009)

    前言 依旧是白嫖账号,只打了一些题/kk 正题 1002 Buying Snacks 题目大意 \(n\)个物品,每个可以买一次也可以不买,如果买需要选择\(1/2\)块钱的,然后也可以相邻两个一起买 ...

  2. CF618F-Double Knapsack【结论】

    正题 题目链接:https://www.luogu.com.cn/problem/CF618F 题目大意 给出大小为\(n\),值域为\([1,n]\)的两个可重集合\(A,B\) 需要你对它们各求出 ...

  3. NVIDIA驱动安装

    在一次重启之后,NVIDIA显卡突然驱动坏了.实验室同学推测可能是有人安装了caffe,导致驱动被升级了.不论如何,需要重装驱动. 我的开发环境:Ubuntu 16.04 + GeForce GTX ...

  4. netty系列之:使用netty搭建websocket客户端

    目录 简介 浏览器客户端 netty对websocket客户端的支持 WebSocketClientHandshaker WebSocketClientCompressionHandler netty ...

  5. 使用 WPF + Chrome 内核实现 在线客服系统 的复合客服端程序

    本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程.本产品已经成熟稳定并投入商用. 免费使用 & 私有化部署免费下载:https://docs.sh ...

  6. 移动端多个DIV简单拖拽功能

    移动端多个DIV简单拖拽功能. 这个demo与之前写的一个例子差不了多少,只是这个多了一层遍历而已. <!DOCTYPE html> <html lang="en" ...

  7. 【原创】xenomai 在X86平台下中断响应时间测试

    1.中断响应时间 实时操作系统的意义就在于能够在确定的时间内处理各种突发的事件,而中断这些事件.系统抢占调度的触发点,因而衡量嵌入式实时操作系统的最主要.最具有代表性的性能指标参数无疑是中断响应时间. ...

  8. 对于caffe程序中出现的Unknown database backend问题的报错怎么办?

    在预处理器中添加USE_LMDB,因为caffe需要一种数据输入格式 这样,在db.cpp中#ifdef USE_LMDB就会变亮,显示使用的数据格式为LMDB

  9. 题解 「2017 山东一轮集训 Day7」逆序对

    题目传送门 Description 给定 $ n, k $,请求出长度为 $ n $ 的逆序对数恰好为 $ k $ 的排列的个数.答案对 $ 10 ^ 9 + 7 $ 取模. 对于一个长度为 $ n ...

  10. 洛谷2149 Elaxia的路线(dp+最短路)

    QwQ好久没更新博客了,颓废了好久啊,来补一点东西 题目大意 给定两个点对,求两对点间最短路的最长公共路径. 其中\(n,m\le 10^5\) 比较简单吧 就是跑四遍最短路,然后把最短路上的边拿出来 ...