国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

C# for Beginner session 10 to 20

2019-11-17 02:41:58
字體:
供稿:網(wǎng)友

C# for Beginner session 10 to 20

Session 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");

}

or can be replaced as:

switch(number)

{

  case:10

  case:20  

  case:30

  Console.WriteLine("you number is{0}",number);

  default:

  Console.WriteLine("you number is not 10 to 30");

}

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

Session 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

Session 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

Session 15for 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.

Session 16Methods 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

Session 17Method 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 int the parameters list,and only have one params paremeter.)

method parameters Vs method arguments

session 18 namespace

namespaces are used to organize your programs

they also provide assistance(幫助) in avoiding(避免) name clashes(沖突)

namespaces don't correspond(對應(yīng)) 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

session 19Introduction 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.

session 20Static 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.


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 扶余县| 金溪县| 德州市| 昌邑市| 黎城县| 禄丰县| 承德市| 宁明县| 鄯善县| 清河县| 兴隆县| 南部县| 秀山| 凤冈县| 樟树市| 鄱阳县| 千阳县| 西平县| 太原市| 揭西县| 武强县| 大港区| 霞浦县| 三台县| 库车县| 岐山县| 绵竹市| 武胜县| 安徽省| 汶川县| 桓台县| 伊通| 临高县| 枣庄市| 定陶县| 娱乐| 乌兰察布市| 南昌市| 南雄市| 丹巴县| 南雄市|