C# language syntax and statement

This article will show and explain you the C# language syntax and statement. 1). Declaring a variable int a; int age,salary; int num=8; string name; string fullname=”amar”; 2). Loop int i=0; While(i Output:-- 0 1 2 3 4 3). For Loop int i=0; for(int i=0;i Output:-- 0 1 2 3 4 4). Do While int i=0; do { Console.WriteLine(i); i++; } while(i output:-- 0 1 2 3 4 Explanation: The output is same as the while loop but main difference is that condition is checked after exceuting the code inside the loop statement 5). Foreach string [] names=new string[]{"ram","varun","aman"}; for each(string name in names) { Console.WriteLine(name); } output:-- ram varun aman Explanation: foreach loop will print the name as it can be used to iterate through a collection like array etc. 6). if...else int age=10; if (age==10) { Console.WrietLine("your age is 10"); } else { Console.WriteLine("I don't know"); } Output:-- your age is 10 Explanation: Execute a statement based on condition 7). Break string [] names=new string[]{"ram","varun","aman"}; for each(string name in names) { Console.WriteLine(name); if(name=="aman") break; } Output:-- ram varun Explanation: Break statement is used to break from Loop statement 8). Continue string [] names=new string[]{"ram","varun","aman"}; for each(string name in names) { Console.WriteLine(name); if(name=="varun") continue; Console.WriteLine("Address"); Console.WriteLine("City"); } Output:-- ram varun Explanation: Continue statement will move to the next iteration of the loop, in above case it will execute the codes, if a continue statement comes it will not execute the code after that and move to the next iteration. 8).Switch statement int age=3; switch(age) { case 10: Console.WriteLine("age=10"); break; case 20: Console.WriteLine("age=20"); break; case 30: Console.WriteLine("age=30"); break; default: Console.WriteLine("No age"); break; } Output:-- age=10 About the author: PlanetSourceCode.in is a place for all developer providing free source codes, articles, MCA complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development
Submitted byAnonymous (not verified)on Thu, 02/10/2011 - 15:51

Good day sir can u help me what is the code when using while loop infinite w/ switch case in one problem.please help me sir.
Submitted bycatya heart garfield (not verified)on Mon, 08/06/2012 - 17:21

Gud day sir, can u help me how to make a program using by grading system... please sir give and exact code.. thank you so much sir.

Add new comment