Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Database Programming Made Easy

This tutorial will teach you step by step on how to connect and manipulate database. If you'd like to suggest a tutorial please write a comment at the bottom of this article.

Read more...

Hire Us to Do Your Work

Do you want a customized system? Do you want to setup your own website to do business? Then we are here to help you in your programming needs.

Read more...

Search

C# language syntax and statement
planetsourcecode's picture
Language: .NET
Category: Miscellaneous

This article will show and explain you the C# language syntax and statement.

1). Declaring a variable

  1. int a;
  2. int age,salary;
  3. int num=8;
  4. string name;
  5. string fullname=”amar”;

2). Loop

  1. int i=0;
  2. While(i<5)
  3. {
  4. Console.WriteLine(i);
  5. ++i;
  6. }

Output:--

0
1
2
3
4

3). For Loop

  1. int i=0;
  2. for(int i=0;i<5;i++)
  3. {
  4. Console.WriteLine(i);
  5. }

Output:--

0
1
2
3
4

4). Do While

  1. int i=0;
  2. do
  3. {
  4. Console.WriteLine(i);
  5. i++;
  6. }
  7. while(i<5);

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

  1. string [] names=new string[]{"ram","varun","aman"};
  2. for each(string name in names)
  3. {
  4. Console.WriteLine(name);
  5. }

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

  1. int age=10;
  2. if (age==10)
  3. {
  4. Console.WrietLine("your age is 10");
  5. }
  6. else
  7. {
  8. Console.WriteLine("I don't know");
  9. }

Output:--

your age is 10

Explanation: Execute a statement based on condition

7). Break

  1. string [] names=new string[]{"ram","varun","aman"};
  2. for each(string name in names)
  3. {
  4. Console.WriteLine(name);
  5. if(name=="aman")
  6. break;
  7. }

Output:--

ram
varun

Explanation: Break statement is used to break from Loop statement

8). Continue

  1. string [] names=new string[]{"ram","varun","aman"};
  2. for each(string name in names)
  3. {
  4. Console.WriteLine(name);
  5. if(name=="varun")
  6. continue;
  7.  
  8. Console.WriteLine("Address");
  9. Console.WriteLine("City");
  10. }

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

  1. int age=3;
  2. switch(age)
  3. {
  4. case 10:
  5. Console.WriteLine("age=10");
  6. break;
  7. case 20:
  8. Console.WriteLine("age=20");
  9. break;
  10. case 30:
  11. Console.WriteLine("age=30");
  12. break;
  13. default:
  14. Console.WriteLine("No age");
  15. break;
  16. }

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

0
Your rating: None



how can make editable listview

please sir give me coding to make editable listview.

planetsourcecode's picture

hi every one

this lesson is dedicated to my friend Jay Pee. thanks buddy

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <java>, <java5>, <javascript>, <mysql>, <php>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • Links to specified hosts will have a rel="nofollow" added to them.

  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Step by Step Java Tutorial

In this tutorial you will learn how to program with Java. It has a rich of information to be educated well with Java.

Read more...

Do You Have Question?

Do you have any question related to computer programming? Visit our forum and post new topic on the category you like. Be gentle when asking a question.

Ask now...

Point of Sale

Point of Sale is very useful especially for supermarkets or restaurants. I have included a barcode scanner in this program. Please check it out.

Read more...