Wednesday, May 28, 2008

Design Patterns

What is Design Pattern?

As Object Oriented

In the Object Oriented design pattern gives the relationship between objects and class.

As Software Engineering

In Software engineering design pattern is general purpose solution of the commonly occur problem. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Why to use design Patterns?

  • Design patterns can speed up the development process by providing tested, proven development paradigms.
  • Effective software design requires considering issues that may not become visible until later in the implementation.
  • Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.

Design Patterns are categorized as …..

Creational Pattern: In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.

Creational Patterns are further categorized as…..

  • Abstract Factory
  • Factory Method
  • Builder
  • Lazy Initialization
  • Prototype
  • Singleton

Structural Pattern In Software Engineering, Structural Design Patterns are Design Patterns that ease the design by identifying a simple way to realize relationships between entities.

Structural Patterns are further categorized as…..

  • Adapter
  • Bridge
  • Composite
  • Decoder
  • Fa├žade
  • Flyweight
  • Proxy

Behavior Patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.

Behavior Patterns are further categorized as…..

  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Observer
  • State
  • Strategy
  • Specification
  • Template method
  • Visitor

Monday, May 26, 2008

Extension Methods

Understanding Extension Methods

In .Net when you define any type and want add new method you want add,remove or update any method in the type then you need to recomplile the type.

Under C# 2008, it is now possible to define extension methods. Methods allows existing compiled types (specifically, classes, structures, well as types currently being compiled (such as types in a project to gain new functionality without needing to directly update this technique can be quite helpful when you need to inject which you do not have an existing code base. It can also be quite type to support a set of members (in the interest of polymorphism), type declaration. Using extension methods, you can add functionality providing the illusion these methods were there all along.

Restriction of Extension Methods:

1) The class contains Extension Method it must be static it means all the stuffs inside are static too.

2) The second point is that all extension methods are marked as such by using this keyword as a modifier on the first (and only the first) parameter of the method in question.

3) The third point is that every extension method can be called either from the correct instance in memory or statically via the defining static class.

Define Extension Method: Create a new console application named it MyExtensions. In that make one class MyExtension (Must be static) in that create one extension method which extends integer data type and add method (ReverseDigits) into it to provide facility to reverse the digits.

static MyExtension
{

public static int ReverseDigits(this int i)
{

// Translate int into a string, and then

// get all the characters.

char[] digits = i.ToString().ToCharArray();

// Now reverse items in the array.

Array.Reverse(digits);

// Put back into string.

string newDigits = new string(digits);

// Finally, return the modified string back as an int.

return int.Parse(newDigits);

}

}

Note that first parameter of the extension method and only first parameter of the extension method must contain this parameter which indicates that type of the first parameter is extended. Extension method may contain more than one parameter.

static class TesterUtilClass
{

// Every Int32 now has a Display() method...


public static void Display(this int i)
{ Console.WriteLine("{0} called the Display() method.", i); }

// ...which has been overloaded to take a string!

public static void Display(this int i, string msg)
{ Console.WriteLine("{0} called Display() and told me: {1}", i, msg); }

}

Invoking Extension Method at Instance Level:

Now look as we have defined the reverse digit method in the integer class it will visible to all integers.

static void Main(string [] args)
{

int myint =123456;
Console.WriteLine(“Value of myint {0}, myint);
Console.WriteLine(“Value of reverse myint {0}, myint.ReverseDigit());

// This will give error because Reverse digit method is only visible to integer datatype.
Bool b1 = true;
b1.ReverseDigit();
}

Invoking Extension Method at Static Level:

Recall that the first parameter of an extension method is marked with the this keyword, followed by the type of item the method is applicable to. If we peek at what is happening behind the scenes (as verified by a tool such as ildasm.exe), we will find that the compiler simply calls the “normal” static method, passing in the variable calling the method as a parameter (e.g., it is the value of this).

public static void Main(string [] args)

{

int myint =12345;
Console.WriteLine(“Revers digit Statically”, MyExtension.ReverseDigit(myint));

}

Scope of Extension Method

When you extending any data type in that extended class you can not use any member of data type you are extending means extending type is not same as inheritance. Let’s take one example.

public class mycar
{

public int speed=6;
public int speedup()
{

++speed;

}
}

Now I am going to extend the mycar class.
public static MycarExtended
{

static int DownSpeed(this car c)
{

//This method is drivring from car so you can’t do this.
-- speed;
}

}

On the above method attempting to access the variable speed. Because DownSpeed is static method of MycarExtended speed does not exists in this context. However you can use this parameter to access only public member of the type. See the below example.

public static MycarExtended
{
static int DownSpeed(this car c)
{

//ok
return -- c.speed;
}

}

Importing type that defines Extension Method:

When you partition a set of static classes containing extension methods in a unique namespace,other namespaces in that assembly will make use of the standard C# using keyword to import not only the static classes themselves, but also each of the supported extension methods. This is important to remember, because if you do not explicitly import the correct namespace, the extension methods are not available for that C# code file.

In effect, although it can appear on the surface that extension methods are global in nature,they are in fact limited to the namespaces that define them or the namespaces that import them.Thus, if we wrap the definitions of our static classes (MyExtensions, TesterUtilClass, andCarExtensions) into a namespace named MyExtensionMethods as shown below

namespace MyExtensionMethods

{

static class MyExtensions

{

...

}

static class TesterUtilClass

{

...

}

static class CarExtensions

{

...

}

}

other namespaces in the project would need to explicitly import the MyExtensionMethods namespace to gain the extension methods defined by these types. Therefore, the following is a compiler

error:

// Here is our only using directive.

using System;

namespace MyNewApp

{

class JustATest

{

void SomeMethod()

{

// Error! Need to import MyExtensionMethods

// namespace to extend int with ReverseDigit()!

int i = 0;

i.ReverseDigit ();

}

}

}

Extending Interface Types via Extension Methods

At this point, you have seen how to extend classes (and, indirectly, structures that follow the same syntax) with new functionality via extension methods. To wrap up our investigation of C# 2008 extension methods, allow me to point out that it is possible to extend an interface type with new methods; however, the semantics of such an action are sure to be a bit different from what you might expect.

Create a new Console Application named InterfaceExtensions and define a simple interface
type (
IBasicMath) that contains a single method named Add(). Next, implement this interface on a class type (MyCalc) in a fitting manner. For example:

// Define a normal CLR interface in C#.

interface IBasicMath

{

int Add(int x, int y);

}

// Implementation of IBasicMath.

class MyCalc : IBasicMath

{

public int Add(int x, int y)

{

return x + y;

}

}

Now, assume you do not have access to the code definition of IBasicMath, but wish to add a

new member (such as a subtraction method) to expand its behavior. You might attempt to author the following extension class to do so:

static class MathExtensions

{

// Extend IBasicMath with subtraction method?
public static int Subtract(this IBasicMath itf,int x, int y);

}

However, this will result in compile-time errors. When you extend an interface with new members,you must also supply an implementation of these members! This seems to fly in the face of the very nature of interface types, as interfaces do not provide implementations, only definitions.
Nevertheless, we are required to define our
MathExtensions class as follows:

static class MathExtensions

{

// Extend IBasicMath this method and this
// implementation.

public static int Subtract(this IBasicMath itf,int x, int y)
{

return x - y;

}

}

At this point, you might assume you could create a variable of type IBasicMath and directly
invoke
Subtract(). Again, if this were possible (which it is not), this would destroy the nature of
.NET interface types. In reality, what we have actually said here is “Any class in my project implementing IBasicMath
now has a Subtract() method, implemented in this manner.” As before, all the basic rules apply, therefore the namespace defining MyCalc must have access to the namespace defining MathExtensions. Consider the following Main() method:

static void Main(string[] args)

{

Console.WriteLine("***** Extending an interface *****\n");

// Call IBasicMath members from MyCalc object.

MyCalc c = new MyCalc();

Console.WriteLine("1 + 2 = {0}", c.Add(1, 2));

Console.WriteLine("1 - 2 = {0}", c.Subtract(1, 2));

// Can also cast into IBasicMath to invoke extension.

Console.WriteLine("30 - 9 = {0}",

((IBasicMath)c).Subtract(30, 9));

// This would NOT work!

// IBasicMath itfBM = new IBasicMath();

// itfBM.Subtract(10, 10);

Console.ReadLine();

}

That wraps up our examination of C# 2008 extension methods. Remember that this particular
language feature can be very useful whenever you wish to extend the functionality of a type, even if you do not have access to the original source code, for the purposes of polymorphism. And, much like implicitly typed local variables, extension methods are a key element of working with the LINQ API. As you will see in the next chapter, numerous existing types in the base class libraries have been extended with new functionality (via extension methods) to allow them to integrate with the LINQ programming model.

Friday, May 23, 2008

Covariance and Contra-variance Delegate

Delegates are pointers to the method to be invoked. In C# 2.0 new features has been introduced known as Covariance and Contra-variance.

Before we proceed consider we class hierarchy like as below

class A{}

Class B: A{}

In our program we have delegate like below

class Program
{
        public delegate A MyDelegate();
        static void Main(string[] args)
{
            MyDelegate delObj = new MyDelegate(CreateObject);
A a = delObj();
}
        public static A CreateObject()
{
return new A();
}
}

Covariance: C# 2.0 provides us flexibility that now when instantiating a delegate the specified method may also have the return type which is the derived form of the return type specified by delegate. For example, now we can instantiate the MyDelegate with a method whose return type is B.

class Program
{
        public delegate A MyDelegate();

static void Main(string[] args)
{
            MyDelegate delObj = new MyDelegate(CreateObject);       
A a = delObj();
}
        public static B CreateObject ()
{
return new B();
}
    }
This is called the covariance. It is not a problem for a compiler also because B (being sub-class of A) can easily be casted to A.
Note: When this functionality was not present in .net 1.x at that time developer need to define two delegates with different return type.


Contravariance:

Suppose we have two classes A and B with A being the parent class of B like

    class A
{
public void ADisplay()
{
Console.WriteLine("A is called...");
}
}
    class B : A
{
public void BDisplay()
{
Console.WriteLine("B is called...");
}
 }
And in our program we defined a delegate which takes a parameter of type B then with C# 1.x, we can instantiate the delegate whose signature is exactly same as that of MyDelegate() that is which takes an object of type B.

 class Program
{
        public delegate void MyDelegate(B bObj);
static void Main(string[] args)
{
            MyDelegate delObj = new MyDelegate(Fun);       
delObj(new B());
Console.ReadLine();
}

public static void Fun(B bObj)
{
bObj.BDisplay();
        }
}

When we run the program it prints the expected output

B is called...

But in C# 2.0, thanks to the contra-variance feature, we can also instantiate the delegate with a method which accepts the parameter of parent type of the type specified by the delegate. For instance in our example, we can instantiate MyDelegate() with a method which accepts an object of type A!

class Program
{
        public delegate void MyDelegate(B bObj);
static void Main(string[] args)
{
            MyDelegate delObj = new MyDelegate(MoreFun);       
delObj(new B());
Console.ReadLine();
        }
        public static void Fun(B bObj)
{
            bObj.BDisplay();
        }
        public static void MoreFun(A aObj)
{
            aObj.ADisplay();
        }
    }



When we run the program, the output is
A is called...


In fact, it is possible because the method being referred MoreFun() accepts an object of type A but the delegate accepts an object of type B. Since, B is a sub-class of A it is possible to cast an object B to type A and pass it to MoreFun().

Anyhow, covariance and contra-variance are really very useful features and it is really good to see these features added to the C# 2.0 programming language.

Association, Aggregation ,Composition, Specialization & Generalization

Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.

Aggregation is a specialize form of Association where all object have their own lifecycle but there is ownership and child object. Let’s take an example of Department and Professor. A single professor can belongs to multiple departments, but if we delete the department teacher object will not destroy. We can think about “has-a” relationship.

Composition is again specialize form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete. Let’s take another example relationship between Questions and options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically delete.

For example, a university owns various departments (e.g., I.T.), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors . In addition, a professors could work in more than one department, but a department could not be part of more than one university.

Composition is usually implemented such that an object contains another object. For example, in C#:

class Professor
{
}
 // If department is deleted professor still exists.
// professor can work more than one department.
class Department // Aggregation
{
private List<professor> professorList = new List<professor>();
}
 // If university is deleted professor department no longer exists.
//department can not be part of more than one university.
class University // Composition
{
           private List<Department> DepartmentList = new List<Department>();
}

Specialization & Generalization

Classes and their instances (objects) do not exist in a vacuum, but rather in a network of interdependencies and relationships, just as we, as social animals, live in a world of relationships and categories.

One of the common relationship is specialization (is a) relationship. For example Dog is Mammal so it has all the characteristics of mammal but reverse is not true. Means some of characteristics present in the dog are not exists in all mammals which are known as specialization. Cat is also mammal so all the characteristics of mammal are present in cat but some characteristics which are different than all mammal which makes it different from Dog which is also mammal.

The specialization and generalization relationships are both reciprocal and hierarchical. Specialization is just the other side of the generalization coin: Mammal generalizes what is common between dogs and cats, and dogs and cats specialize mammals to their own specific subtypes.

These relationships are hierarchical because they create a relationship tree, with specialized types branching off from more generalized types. As you move "up" the hierarchy, you achieve greater generalization. You move up toward Mammal to generalize that dogs, cats, and horses all bear live young. As you move "down" the hierarchy you specialize. Thus, the cat specializes Mammal in having claws (a characteristic) and purring (a behavior).

Similarly, when you say that ListBox and Button are Windows, you indicate that there are characteristics and behaviors of Windows that you expect to find in both of these types. In other words, Window generalizes the shared characteristics of both ListBox and Button, while each specializes its own particular characteristics and behaviors.


Automatic Properties

Automatic Properties
If you are already c# developer and you are developing classes with properties as shown below.


public class Student

{

private string _firstName;
private string _lastName;
private int _age;

public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}

public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

public int Age
{

get { return _age;}
set {_age = value;}
}

}

as mention above we are not applying any logic in the getters/setters of our properties but instead we just get/set the value directly to a field. so there is question in our mind that instead of that why not just use fields instead of properties? There are losts of downsides to exposing public fields.

Few problems are mention below.

1) You can't easily data bind against fields

2) If you expose public fields from your classes you can't later change them to properties (for example: to add validation logic to the setters) without recompiling any assemblies compiled against the old class.

The new C# compiler that ships in "Orcas" has new feature named "Automatic Properties". Automatic properties allow you to avoid having to manually declare a private field and write the get/set logic -- instead the compiler can automate creating the private field and the default get/set operations for you.

As above example I have to write just as bellow.

public class Student
{

public string FirstName { get; set; }
public string LastName { get; set; }

public int Age { get; set; }

}

When the C# "Orcas" compiler encounters an empty get/set property implementation like above, it will now automatically generate a private field for that within class, and implement a public getter and setter property implementation to it. The benefit of this is that from a type-contract perspective, the class looks exactly like it did with our first (more verbose) implementation above. This means that unlike public fields I can in the future add validation logic within my property setter implementation without having to change any external component that references my class.

Above code some what like abstract property inside the abstract class but it is different than the code mention below.

public abstaract class Student
{

public abstract string FirstName { get; set; }

}

Automatic private field generated by complier can not be viewed directly it can be seen only in the ILDASM.exe.

Limitations of Automatic Properties

1) You can not define read-only and write only properties.

// Read-only property? Error!

public int MyReadOnlyProp { get; }

// Write only property? Error!

public int MyWriteOnlyProp { set; }

Above code will give you compile time error it must have both read and write properties.

2) As mention that private backing field for the public property is generated by the compiler run time. Developer can use only the public property in his/her code. He/she can’t user private field in the code. In below example I have custom class which implements ToString() which can't use private field.

class Employee

{

public string FirstName { get; set; }
public override string ToString()
{

// No access to the private member in the defining
// class. Must use properties!
// you can not use here private filed since it is not visible here it will be
// generated by compiler

return string.Format("Employee First Name = {0}", FirstName);

}

}

Restrict Access on Automatic Properties:

As In the C# 2.0 we were able to set the access modifier to getter ans setter in automatic property it is also possible.

// Anyone can get the FirstName value, but
// only the defining type and the children can set it.

public int FirstName

{

get { return firstName; }
protected set { firstName = value; }

}

This same possibility is allowed using automatic property syntax as follows:

public string FirstName { get; protected set; }

Of course, with this update, the Main() method would now generate a compiler error when attempting to assign the value of the FirstName property:

static void Main(string[] args)

{

...
// Error! Setting the
FirstName is only possible
// from within the Employee type or by a child type!

e. FirstName = "Tejas";

// Getting the value is still OK.

Console.WriteLine("Your FirtName is {0}? ...", e.FirstName);

Console.ReadLine();

}

Regarding Automatic Properties and Default Values

When you use automatic properties to encapsulate numerical or Boolean data, you are able to use the auto generated type properties straightaway within your code base, as the hidden backing fields will be assigned a safe default value that can be used directly. However, be very aware that if you use automatic property syntax to wrap a reference type, the hidden private reference type will also be set to a default value of null:

class EmployeeCollection

{

// The hidden int backing field is set to zero!
public int NumberOfEmployee { get; set; }

// The hidden Employee backing field is set to null!
public Employee GEmployee { get; set; }

}

Given C#’s default values for field data, you would be able to print out the value of

NumberEmployee as is (as it is automatically assigned the value of zero), but if you directly invoke Employee, you will receive a null reference exception:

static void Main(string[] args)

{

...

EmployeeCollection e = new EmployeeCollection ();

// OK, prints defualt value of zero.

Console.WriteLine("Number of Employee: {0}", e.NumberOfEmployee);

// Runtime error! Backing field is currently null!

Console.WriteLine(e.GEmployee. FirstName);

Console.ReadLine();

}

Given that the private backing fields are created at compile time, you will be unable to make use of C# field initialization syntax to allocate the reference type directly with the new keyword. Therefore, this work will need to be done with type constructors to ensure the object comes to life in a safe manner. For example:

class EmployeeCollection

{

// The hidden backing field is set to zero!
public int NumberOfEmployee { get; set; }

// The hidden backing field is set to null!
public Employee GEmployee { get; set; }

// Must use constructors to override default
// values assigned to hidden backing fields.

public EmployeeCollection ()
{

GEmployee = new Employee ();
NumberOfEmployee = 1;
}

public EmployeeCollection (Employee emp, int number)

{

GEmployee = emp;
NumberOfEmployee = number;
}

}

As you most likely agree, this is a very nice extension to the C# programming language, as you can define a number of properties for a class using a streamlined syntax. Be aware of course that if you are building a property that requires additional code beyond getting and setting the underlying private field (such as data validation logic, writing to an event log, communicating with a database, etc.), you will be required to define a “normal” .NET property type by hand. C# 2008 automatic properties never do more than provide simple encapsulation for an underlying data type.

Wednesday, May 21, 2008

Implicitly typed local variables (var – Contextual Keyword)

Implicitly typed local variables (var – Contextual Keyword)

Suppose I have created console application named ExplicitVars. Code given below all the variables are known as explicitly defined.

static void ExplicitVars()
{

// Explicitly typed local variables
// are declared as follows:
// dataType variableName = initialValue;

int ExplicitInt = 0;
bool ExplicitBool = true;
string ExplicitString = "go catch it...";
}

C# has introduced new token known as "var" which can decide the data type of the variable based on the value assigned to it. Above mention code can be written as.

static void ImplicitVars()
{

// implicitly typed local variables
// are declared as follows:
// var variableName = initialValue;

var ImplicitInt = 0;
var ImplicitBool = true;
var ImplicitString = " go catch it...";
}


When you see the types of each variable defined above it will be converted automatically by compiler based on the value assigned to it.

static void ImplicitVars()
{

// Implicitly typed local variables.
var ImplicitInt = 0;
var ImplicitBool = true;
var ImplicitString = "Time, marches on...";

// Print out the underlying type.
Console.WriteLine("myInt is a: {0}", ImplicitInt.GetType().Name);
Console.WriteLine("myBool is a: {0}", ImplicitBool.GetType().Name);
Console.WriteLine("myString is a: {0}", ImplicitString.GetType().Name);

}


Implicitly type conversion can be used also with arrays, generics and custom types.

static void ImplicitVars()
{

// More implicitly typed local variables.
var evenNumbers = new int[] { 2, 4, 6, 8 };
var myMinivans = new List();
var myCar = new SportsCar();

Console.WriteLine("evenNumbers is a: {0}", evenNumbers.GetType().Name);
Console.WriteLine("myMinivans is a: {0}", myMinivans.GetType().Name);
Console.WriteLine("myCar is a: {0}", myCar.GetType().Name);
}


You can also use the "var" inside for loops like below...

static void VarInForeachLoop()
{

var oddNumbers = new int[] { 1, 3, 5, 7 };

// Use "var" in a standard foreach loop.

foreach (var item in oddNumbers)
{
Console.WriteLine("Item value: {0}", item);
}

// Use a strongly typed System.Int32 to iterate over contents.
foreach (int item in oddNumbers) // it also works fine.
{
Console.WriteLine("Item value: {0}", item);
}
}

Limitations in Implicitly Typed Variables:

1) You can not use "var" as return values, parameter of method or field of any type. "Var” can be used inside method or roperty scope only.

class NeverCompile
{

// Error! var cannot be used as field data!
private var ImplicitInt = 100;

// Error! var cannot be used as a return value
// or parameter type!
public var ImplicitMethod(var p, var q){}
}

2) Variable defined using "var" must assigned initial value at the time of declaration and it should be null.

// Error! Must assign a value!
var ImplicitData;

// Error! Must assign value at exact time of declaration!
var ImplicitInt;
ImplicitInt= 0;

// Error! Can't assign null as initial value!
var refrenceType = null;

However it is possible to assign value null once it is recognized as reference type as below.

// OK, is fruit is a reference type!
var fruit = new Apple();
fruit = null;

However it is possible to assign value of implicit var to another varible either implicit or typed.

// Also OK!
var myInt = 0;
var anotherInt = myInt;
string myString = "Wake up!";
var myData = myString;

Following code also work fine.
static int ReturnVar()
{
var retVal = 999;
return retVal;

}

3) Nullable Implicit Type local is not possible.
var? notposible = null;//Error
var? i =0;//Error

Implicitly Typed variable is strogly typed variable.

Once value is assigned to the variable defined using var you can not change it's value which represents the different datatype. Means it is not same as used in VB using var or used in the scripting laguage like VBScript or javaScript. see the below code.

static void ImplicitTypingIsStrongTyping()
{

// The compiler knows "s" is a System.String.

var s = "This variable can only hold string data!";

s = "This works no error at all!...";

// Can invoke any member of the underlying type.
string upper = s.ToUpper();

// Error! Can't assign numerical data to a a string!
s = 44;

// Error! Can't perform this operation with string!
s = "Tejas" + 44;
}


When to User "var" ?

Generally if you know that variable will hold integer value then there is no need to declare it as var. you can declare it as int datatype but var token can be used with the LINQ query largely because output of the LINQ query can be vary on the based of the select statement when query so it is the best way to use var in the LINQ query.

Note: var is Contextual Keyword of C#. You can declare variable like int var =0 compiler will not give any error, but when it is used as var i=0 then complier treats "var" as contextual keyword.

What do you mean by Contextual Keyword?
A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#. The following contextual keywords are introduced in this section:

get Defines an accessor method for a property or an indexer.
partial Defines partial classes, structs, and interfaces throughout the same compilation unit.
set Defines an accessor method for a property or an indexer.
where Adds constraints to a generic declaration.
yield Used in an iterator block to return a value to the enumerator object or to signal the end of iteration.
value Used to set accessors and to add or remove event handlers.

All query keywords introduced in C# 3.0 are also contextual. See Query Keywords (C# Reference).

See Also
Concepts

C# Reference
C# Programming Guide
C# Keywords