Tips & Ticks by SAJJAD
Posts tagged Keywords
C# virtual Keywords: More speed
Oct 14th
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Area of 5 is: " + (new Circle(5).Area()).ToString());
Console.WriteLine("Perimeter of 5 is: " + (new Circle(5).Perimeter()).ToString());
Circle C = new Circle(8.5);
Console.WriteLine("\nArea of 8.5 is: " + C.Area().ToString());
Console.WriteLine("Perimeter of 8.5 is: " + C.Perimeter().ToString());
Console.Read();
}
}
abstract class Shape
{
public double X, Y;
public Shape() : this(0) { }
public Shape(double X)
{
this.X = this.Y = X;
}
public Shape(double X, double Y)
{
this.X = X;
this.Y = Y;
}
public virtual double Area()
{
return this.X * this.Y;
}
public virtual double Perimeter()
{
return 2 * this.X * this.Y;
}
}
sealed class Circle : Shape
{
public Circle() : base(0) { }
public Circle(double Radius) : base(Radius) { }
public override double Area()
{
return Math.PI * this.X * this.X;
}
public override double Perimeter()
{
return 2 * Math.PI * this.X;
}
}
}
C# params Keywords
Oct 14th
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
if (Containt(typeof(int), new object[] { true, 1, 110.1F, 20L, 80.0001D, "SAJJAD", DateTime.Now }))
{
Console.WriteLine("Array contain Int32 type !");
}
if (Containt(typeof(DateTime), true, 1, 110.1F, 20L, 80.0001D, "SAJJAD", DateTime.Now))
{
Console.WriteLine("Array contain Datetime type !");
}
Console.ReadLine();
}
static bool Containt(Type type, params object[] list)
{
foreach (object obj in list)
if (obj.GetType() == type)
return true;
return false;
}
}
}
C# Reserved and Contextual Keywords
Oct 8th
Specification keywords
abstract | as | base | bool | break | byte | case | catch | char | checked | class | const | continue | decimal | default | delegate | do | double | else | enum | event | explicit | extern | false | finally | fixed | float | for | foreach | goto | if | implicit | in | int | interface | internal | is | lock | long | namespace | new | null | object | operator | out | override | params | private | protected | public | readonly | ref | return | sbyte | sealed | short | sizeof | stackalloc | static | string | struct | switch | this | throw | true | try | typeof | uint | ulong | unchecked | unsafe | ushort | using | virtual | void | volatile | while
Magic keywords
__arglist | __makeref | __reftype | __refvalue
Keywords as an identifier
@typeof @goto = @for.@switch(@throw);
Preprocessor keywords
#define | hidden | default | disable | restore | checksum
C# 1.0 Contextual keywords
get | set | value | add | remove
C# 2.0 Contextual keywords
where | partial | global | yield | alias
C# 3.0 Contextual keywords
from | join | on | equals | into | orderby | ascending | descending | group | by | select | let | var
C# 4.0 Contextual keywords
dynamic
Recent Comments