Q. What is static class?
Ans. Static class can contain only static members, which are
static methods, static fields, and static variable. The advantage of using a
static class is that the Static classes are sealed and therefore cannot be
inherited.It's memeber can be accessed throuh only class name
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationstactic
{
class Program
{
public static int C = 10; //Static variable
public static double calres(int A, int B) //Static method
{
return A * B;
}
static void Main(string[] args)
{
Double Area;
Area = Program.calres(10, 5)+C; //Static variable are called with class name
Console.WriteLine("Result is={0}",Area);
Console.Read();
}
}
}
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationstactic
{
class Program
{
public static int C = 10; //Static variable
public static double calres(int A, int B) //Static method
{
return A * B;
}
static void Main(string[] args)
{
Double Area;
Area = Program.calres(10, 5)+C; //Static variable are called with class name
Console.WriteLine("Result is={0}",Area);
Console.Read();
}
}
}

0 Comments