We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Thursday, February 26, 2015

Q.What is void keyword in c# and give a example?

Q.What is void keyword in c# and given one example?

A void is empty. The void keyword in the C# language indicates that a method returns nothing.
When a void method is invoked,
it has no result and no variable can be assigned. Void is useful throughout our source code.


EXAMPLE:-

C# program that declares void type methods
 
using System;

class Program
{
    static void Example1()
    {
 Console.WriteLine("Static void method");
    }
    void Example2()
    {
 Console.WriteLine("Instance void method");
 return; // Optional
    }

    static void Main()
    {
 
 // Invoke a static void method.
 
 Example1();

 // Invoke an instance void method.
 
 Program program = new Program();
 program.Example2();
 
 // This statement doesn't compile.

 // int x = Example1();
    }
}

Output

Static void method
Instance void method 

 

No comments: