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:-
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:
Post a Comment