Keywords are predefined and reserved identifiers for .net compiler, which cannot be used while writing any program in C#.
Apart from Access Modifiers (public, private, protected) here are some Most Used Keywords in C#
using keyword normally used for adding namespace reference, but also can be used for adding for defining a block for new instance, let’s look at the example below.
using System.Text;
using WebTrainingRoom.BO
//now creating a new object of any class
using(Student stu=new Student())
{
}
Class is a keyword used for Creating a class in C# .Net, here is a simple example.
using System;
public class TrainingRoom
{
// define properties and methods here.
}
Learn more about C# Class
enum EventState
{
Gif = 1,
Jpg = 2
}
sealed class SealedExample
{
public int getTotal(int x, int y)
{
return x + y;
}
}
class MyAccont
{
public volatile int balance;
public void Update(int i)
{
balance = i;
}
}
unsafe static void DOWork(int p)
{
}
public class Car
{
protected internal int EngineNumber { get; set; }
}
class TestClass
{
[DllImport("User32.dll"]
public static extern string MessageBox(string message);
static void Main()
{
Console.Write("Enter message : ");
string myMsg = Console.ReadLine();
MessageBox(myMsg);
}
}
public abstract class Car
{
public abstract string color { get; set; }
public virtual int Number { get; set; }
}
public class Maruti: Car
{
public override string color { get; set; }
public override int Number { get; set; }
}
Car myCar=New Car();
public static async void Execute()
{
// running this method asynchronously.
int t = await Task.Run(() => Calculate());
Console.WriteLine("Result: " + t);
}
partial class TrainingBase
{
public abstract string Title { get; set; }
}
partial class TrainingBase
{
public abstract DateTime TrainingDate { get; set; }
}
abstract keyword can be used for declaring abstract class, property, method
abstract class TrainingBase
{
public abstract string Title { get; set; }
public abstract DateTime TrainingDate { get; set; }
}
interface ITraining
{
string Title { get; set; }
string Trainer { get; set; }
string TrainingDate { get; set; }
}
Here are some c# Interface example.
Car myCar=null;
try
{
// our code.
}
catch(Exception ex)
{
throw;
}