C# Empty Statement(;)

In this chapter you will learn:
  • What is Empty Statement in C#?
  • How to use Empty Statement in C#?
  • What is the benefit of using Empty Statement in C#?

An empty statement is used when you no need to perform an operation where a statement is required. It simply transfers control to the end point of the statement. It is also very useful with a while loop with the blank body and label statements.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace empty_statements
{
    class Program
    {
        public bool print()
        {
            Console.WriteLine("Steven Clark");
            return true;
        }
        static void Main(string[] args)
        {
            int i = 0;
            Program p = new Program();
            while (p.print())
            {
                ; //Empty Statement
            }
            Console.WriteLine("i = {0}", i);
            Console.ReadLine();
        }
    }
}

  Note: It processes infinite loop so terminating the program press ctrl+c.

Output

Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
Steven Clark
__

Summary

In this chapter you learned about empty statement in C#. You also learned how to use empty statement in C# programming. In next chapter you will learn about goto statement in C#.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.