Pages

Monday, July 25, 2011

Nested Classes in C#


class Demo
{     public static void Main()    
   {
      System.Console.WriteLine("Demo");      
      OuterClass.NestedClass nc = new OuterClass.NestedClass();     
   }
}

class OuterClass
  {
      public OuterClass()
     {
        System.Console.WriteLine("OuterClass");     
      }   
      public class NestedClass 
      {   
       public NestedClass()    
       {   
         System.Console.WriteLine("NestedClass");      
        }
   }
 }

Output

Demo  NestedClass
The above program compiles and runs successfully to give the desired output. An attempt was made to create an object of NestedClass. Therefore the constructor of NestedClass got executed. There is no reason why the constructor of OuterClass should get executed.

Friday, July 15, 2011

Questions Answers

Q:Difference between Clustered and Non-Clustered Index Data Structures?

When you first create a new table, there is no index created by default. In technical terms, a table without an index is called a “heap”. As you would expect, the data we will insert into the table will be returned in the same order. A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.
A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.
Clustered index is good when you know in which order you will be returning the records in most cases. You can create clustered index and after that you don’t need to use ORDER BY statement. This will be much more faster. If the order is not important for you and will not create clustered index by yourself, then primary key will be clustered index by default. There is nothing bad not to have the clustered index, it can speed up inserting rows.
Source:- http://www.allinterview.com/showanswers/8164.html

Q:Difference between Trace and Debug ?

According to Microsoft Documentation there is not much
difference between Trace and Debug Class.

Debug only works in debug mode and trace works in debug and
release both mode.


Q:Difference between Array and ArrayList?

Array is the collection of values of the same data type
>the variables in an array is called array elements
>Array is a reference type data type
>The array structure in System's Memory

Array list is a class .
>when you want to access the elements of an array through its index value location in an array,use an ArrayList.
>The use of the arraylist is an alternative to the use of th array.
>The Methods Of ArrayList class are
1)Add
2)Remove
3)Clear
4)Insert
5)TrimToSize
6)Sort
7)Reverse

Example: http://stackoverflow.com/questions/459677/c-a-strings-split-method

Question: difference between ref and out

The main difference between the two types is in the rule for definite assignment of them.
When we use the out parameter, The program calling the function need not assign a value to the out parameter before making the call to the function. The value of the out parameter has to be set by the function before returning the value.
The same is not true for the reference (ref) type parameter. For a ref type parameter, the value to the parameter has to be assigned before calling the function. If we do not assign the value before calling the function we will get a compiler error.

Another important thing to note here is that in case of ref parameter, the value passed by the caller function can be very well used by the called function. The called function does not have the compulsion to assign the value to a ref type parameter. But in case of the out parameter, the called function has to assign a value.

nhibernate-mapping-concurrency

Thursday, July 14, 2011

Creating Full Text Catalog and Full Text Search

Object Oriented Programming - Concepts

Object Oriented Programming

OOP is Nothing but Object Oriented Programming.
In OOPs concept is implimented in our real life systems.
OOPs have following features
1. Object - Instance of class
2. Class - Blue print of Object
3. encapsulation - Protecting our data
4. polymorphism - Different behaviors at diff. instances
5. abstraction - Hidding our irrelavance data
6. inheritence - one property of object is aquring to
another property of object

Simple Ex.
Please assume u standing near a car.
How to impliments our OOPs concept for this scenario ?
Simple,
car is a object b'coz it having more functions.
car is a class b'coz it contain more parts and features inside.
car is a Encapsulation B'coz it protected some unwanted parts or
functions to user car is a Polymorphism b'coz it have different
speed as display in same speedometer car is a Abstraction b'coz
it hidding more parts by coverig such as engine,disel tank car
is a Inheritance b'coz one car is a property of more people.
i mean your car is driving bu you, your friend and your relatives.

Wonderful source link for OOPS concepts:-
http://www.desy.de/gna/html/cc/Tutorial/tutorial.html


Q:what is difference between instance and object.?
instance means just creating a reference(copy) .
object :means when memory location is associated with the object( is a runtime entity of the class) by using the new operator

Q:what are the all difference between interface and abstract class?
interface is a set of abstract methods, all of which have to be overriden by the class whichever implements the interface
abstract class is a collection of data and methods which are abstact (not all of them)

Interfaces are essentially having all method prototypes no definition but Abstract class can contain method definations also.

In short Interface is a abstract class having all methods abstract.
Both abstract classes and interfaces are used when there is a difference in behaviour among the sub-types extending the abstract class or implementing the interface.

When the sub-types behaviour is totally different then you use an interface, when the sub-types behaviour is partially common and different with respect to the supertype an abstract class is used. In an abstract class the partially common behaviour is given a concrete implementation. Since there is no common behaviour between an interface and a sub-type an interface does not have an implementation for any of its behaviour.
If you create a abstract class writing the abstract keyword in the declaration part then You only can inherit the class. You can not create an instance of this abstract class but can inherit the class and with creating the instance of the derived class you can access the method of the abstract class.

If you use a virtual keyword in a method then you can override this method in the subclass if you wish..
If you create a abstract method then you must override this method in the subclass other wise it shows error in the program.


1) What is meant by Object Oriented Programming?
OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
Class is a template for a set of objects that share a common structure and a common behavior.

3) What is an Object?
Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

4) What is an Instance?
An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?
Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?
Encapsulation is the process of compartmentalizing the elements of an abstraction that defines the structure and behavior. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

What is meant by Inheritance?
Inheritance is a relationship among classes, wherein one class shares the structure or behavior defined in another class. This is called Single Inheritance. If a class shares the structure or behavior from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalized superclasses.
9) What is meant by Polymorphism?
Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.
10) What is an Abstract Class?
Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behavior, typically by implementing its abstract operations.

11) What is an Interface?
Interface is an outside view of a class or object which emphasizes its abstraction while hiding its structure and secrets of its behavior.

12) What is a base class?
Base class is the most generalized class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

13) What is a subclass?
Subclass is a class that inherits from one or more classes
14) What is a superclass?
superclass is a class from which another class inherits.

15) What is a constructor?
Constructor is an operation that creates an object and/or initializes its state.

16) What is a destructor?
Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.
17) What is meant by Binding?
Binding denotes association of a name with a class.

18) What is meant by static binding?
Static binding is a binding in which the class association is made during compile time. This is also called as Early binding.

19) What is meant by Dynamic binding?
Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) Define Modularity?
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

21) What is meant by Persistence?
Persistence is the property of an object by which its existence transcends space and time.

22) What is collaboration?
Collaboration is a process whereby several objects cooperate to provide some higher level behavior.

23) In Java, How to make an object completely encapsulated?
All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables.

24) How is polymorphism achieved in java?
Inheritance, Overloading and Overriding are used to achieve Polymorphism in java.

25) What is sealed and abstract class?

Source link:- http://msdn.microsoft.com/en-us/library/ms173150%28v=vs.80%29.aspx

Compile time polymorphism is functions and operators overloading.
Runtime time polymorphism is done using inheritance and virtual functions.
eg compile time polymorphism -- method overloding

run time time polymorphism -- method overriding

Static classes and static methods

  1. Static Class occupy memory during compile time.
  1. Static class cannot be instantiated. It calls its data members and member functions itself.
  1. Static class can have static members only as its cannot declare instance members in a static class
  1. Static class constructor get called whenever any static member is called.
  1. General Class can contains static methods but they too called its-self by class name.

Wednesday, July 13, 2011

Extension Methods in C#

using System;

namespace Foo
{
   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(2.DoubleThenAdd(3));
            Console.WriteLine(IntHelper20.DoubleThenAdd(2, 3));
            Console.ReadLine();
        }
    }

    public static class IntHelper20
    {
        public static int DoubleThenAdd(int myInt, int x)
        {
            return myInt + (2 * x);
        }
    }

    public static class IntHelper35
    {
        public static int DoubleThenAdd(this int myInt, int x)
        {
            return myInt + (2 * x);
        }
    }
}



Source: http://www.hanselman.com/blog/HowDoExtensionMethodsWorkAndWhyWasANewCLRNotRequired.aspx