Translate

Monday 23 December 2013

ASP.net c# Avoid open the same window twice

http://blog.startq.com/index.php/2013/03/28/prevent-multiple-tabs-on-c-web-applications/

http://stackoverflow.com/questions/10336312/asp-net-c-sharp-avoid-open-the-same-window-twice

http://www.codeproject.com/Articles/35859/Detect-and-prevent-multiple-windows-or-tab-usage-i

 http://jinaldesai.net/stop-sharing-session-state-between-multiple-tabs-of-browser/

Window features in window.open()

The table below lists the string features you can pass into the "feature" parameter of window.open() to manipulate its interface. Most features support a value of true or false, though in general, simply including the name of the feature implies it should be added to the window (yes), while not including it means it shouldn't (no). Separate each feature with a comma (,).
Feature Description
channelmode Specifies if window should be opened in channel mode. IE only.
fullscreen Specifies if window should be opened in full screen mode. IE only.
height Specifies the height of the window.
left Specifies the x coordinates of the window in pixels. IE only. See "screenX" as well.
location Specifies if the location bar of the window should be included.
menubar Specifies if the menu bar of the window should be included.
resizable Specifies if window should be resizable.
screenX Specifies the x coordinates of the window in pixels. NS only. See "left" as well.
screenY Specifies the y coordinates of the window in pixels. NS only. See "top" as well.
scrollbars Specifies if window should contain scrollbars
status Specifies if the status bar of the window should be included
toolbar Specifies if the toolbar of the window (i.e., reload button) should be included.
top Specifies the y coordinates of the window in pixels. IE only. See "screenY" as well.
width Specifies the width of the window.

Sunday 22 December 2013

Sql Query

/* Delete Duplicate records */
WITH CTE (COl1,Col2, DuplicateCount)
AS
(
SELECT COl1,Col2,
ROW_NUMBER() OVER(PARTITION BY COl1,Col2 ORDER BY Col1) AS DuplicateCount
FROM DuplicateRcordTable
)
DELETE
FROM
CTE
WHERE DuplicateCount > 1
GO

----------------------------------------------------------------------------------------


SQL SERVER – 2008 – 2005 – Rebuild Every Index of All Tables of Database – Rebuild Index with FillFactor

 DECLARE @TableName VARCHAR(255)
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET
@fillfactor = 80
DECLARE TableCursor CURSOR FOR
SELECT
OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET
@sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@sql)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE
TableCursor
DEALLOCATE TableCursor
GO

-------------------------------------------------------------------------------------------
http://iis-7.blogspot.in/2012/09/iis-interview-questions.html
http://www.dotnetfunda.com/interviews/cat/122/iis
http://www.scribd.com/doc/94909071/IIS-Interview-Questions-and-Answers
http://www.iis.net/learn/web-hosting/frequently-asked-questions-%28faq%29/general-iis7-questions

Saturday 21 December 2013

ASP .net Page Life cycle (Background Process)


Background 

IIS: IIS (Internet Information Server) is a complete Web server that makes it possible to quickly and easily deploy powerful Web sites and applications. It is the default web server used with .NET. When a Web server (for ASP.NET applications, typically IIS) receives a request, it examines the file-name extension of the requested file, determines which ISAPI extension should handle the request, and then passes the request to the appropriate ISAPI extension. (By default, ASP.NET handles file name extensions that have been mapped to it, such as .aspx, .ascx, .ashx, and .asmx.) 

ISAPI
Internet Server Application Programming Interface (ISAPI), is an API developed to provide the application developers with a powerful way to extend the functionality of Internet Information Server (I IS). Although ISAPI extensions by no means are limited to IIS, they are extensively used in conjunction with MS-I IS.
Note:
  1. *****If a file name extension has not been mapped to ASP.NET, ASP.NET will not receive the request. It will be handled by the IIS. The requested page/image/file is returned without any processing.
  2. *****If you create a custom handler to service a particular file name extension, you must map the extension to ASP.NET in I IS and also register the handler in your application's Web.config file.
ASPNET_ISAPI.DLL: This DLL is the ISAPI extension provided with ASP.NET to process the web page requests. I IS loads this DLL and sends the page request to this DLL. This DLL loads the HttpRuntime for further processing.

ASPNET_WP.EXE: Each worker process (ASPNET_WP.EXE) contains an Application Pool. Each Application Pool can contain any number of Applications. Application Pool is also called as AppDomain. When a web page is requested, IIS looks for the application pool under which the current application is running and forwards the request to the respective worker process.

HTTP Pipeline: HTTP Pipeline is the general-purpose framework for server-side HTTP programming that serves as the foundation for ASP.NET pages as well as Web Services. All the stages involved from creating HTTP Runtime to HTTP Handler are called HTTP Pipeline.

HTTP Runtime: Each AppDomain has its own instance of the HttpRuntime class—the entry point in the pipeline. The HttpRuntime object initializes a number of internal objects that will help carry the request out. The HttpRuntime creates the context for the request and fills it up with any HTTP information specific to the request. The context is represented by an instance of the HttpContext class. Another helper object that gets created at such an early stage of the HTTP runtime setup is the text writer—to contain the response text for the browser. The text writer is an instance of the HttpWriter class and is the object that actually buffers any text programmatically sent out by the code in the page. Once the HTTP runtime is initialized, it finds an application object to fulfill the request. The HttpRuntime object examines the request and figures out which application it was sent to (from the pipeline's perspective, a virtual directory is an application).

HTTP Context: This is created by HTTP Runtime. The HttpContext class contains objects that are specific to the current page request, such as the HttpRequest and HttpResponse objects. You can use this class to share information between pages. It can be accessed with Page.Context property in the code.

HTTP Request
: Provides access to the current page request, including the request headers, cookies, client certificate, query string, and so on. You can use this class to read what the browser has sent. It can be accessed with
Page.Request property in the code.

HTTP Response: Provides access to the output stream for the current page. You can use this class to inject text into the page, to write cookies, and more. It can be accessed with Page.Response property in the code.

HTTP Application: An application object is an instance of the HttpApplication class—the class behind the global.asax file. HttpRuntime uses HttpApplicationFactory to create the HttpApplication object. The main task accomplished by the HTTP application manager is finding out the class that will actually handle the request. When the request is for an .aspx resource, the handler is a page handler—namely, an instance of a class that inherits from Page. The association between types of resources and types of handlers is stored in the configuration file of the application. More exactly, the default set of mappings is defined in the <httpHandlers> section of the machine.config file. However, the application can customize the list of its own HTTP handlers in the local web.config file. The line below illustrates the code that defines the HTTP handler for .aspx resources.
Collapse
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>

HttpApplicationFactory: Its main task consists of using the URL information to find a match between the virtual directory of the URL and a pooled HttpApplication object.

HTTP Module: An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request. They also let you examine the outgoing response and modify it. ASP.NET uses modules to implement various application features, which include forms authentication, caching, session state, and client script services. In each case, when those services are enabled, the module is called as part of a request and performs tasks that are outside the scope of any single page request. Modules can consume application events and can raise events that can be handled in the Global.asax file.

HTTP Handler: An ASP.NET HTTP handler is the process that runs in response to a request that is made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page handler. We can write our own handler and handler factory if we want to handle the page request in a different manner.
Note: HTTP modules differ from HTTP handlers. An HTTP handler returns a response to a request that is identified by a file name extension or family of file name extensions. In contrast, an HTTP module is invoked for all requests and responses. It subscribes to event notifications in the request pipeline and lets you run code in registered event handlers. The tasks that a module is used for are general to an application and to all requests for resources in the application.
-----------------------------------------------------------------------------------------------------------------------------

Life Cycle of Page
  1. Web page request comes from browser.
  2. IIS maps the ASP.NET file extensions to ASPNET_ISAPI.DLL, an ISAPI extension provided with ASP.NET.
  3. ASPNET_ISAPI.DLL forwards the request to the ASP.NET worker process (ASPNET_WP.EXE or W3P.EXE).
  4. ISAPI loads HttpRuntime and passes the request to it. Thus, HTTP Pipelining has begun.
  5. HttpRuntime uses HttpApplicationFactory to either create or reuse the HttpApplication object.
  6. HttpRuntime creates HttpContext for the current request. HttpContext internally maintains HttpRequest and HttpResponse
  7. HttpRuntime also maps the HttpContext to the HttpApplication which handles the application level events.
  8. HttpApplication runs the HTTP Modules for the page requests.
  9. HttpApplication creates HttpHandlers for the page request. This is the last stage of HTTPipelining.
  10. HttpHandlers are responsible to process request and generate corresponding response messages.
  11. Once the request leaves the HTTPPipeline, page level events begin.
  12. Page Events are as follows: PreInit, Init, InitComplete, PreLoad, Load, Control events (Postback events), Load Complete, PreRender, SaveStateComplete, Render and Unload.
  13. HTTPHandler generates the response with the above events and sends back to the IIS which in turn sends the response to the client browser.


Events in the Life Cycle of Page

PreInit:
All the Pre and Post events are introduced as part of .NET Framework 2.0. this event is fired before the Init method is fired. Most common functionalities implemented in this method include:
  1. Check the IsPostBack property
  2. Set the master page dynamically
  3. Set the theme property of the page dynamically
  4. Read or Set the profile property values
  5. Re-create the dynamic controls
Init:
This event is raised after all controls in the page are initialized and any skin settings have been applied. This event is used to read or initialize control properties. It can be used to register events for some controls for which the events are not specified in the aspx page.


Ex: OnClick event of the Button can be registered in the Init rather than specifying in the OnClick property of the Button in the aspx page.
InitComplete:
Use this event for processing tasks that require all initialization to be complete.
PreLoad:
Use this event if you need to perform processing on your page or control before the Load event. After the Page raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Load:
The Page calls the OnLoad event method on the Page, then recursively does the same for each child control, which does the same for each of its child controls until the page and all controls are loaded. Use the OnLoad event method to set properties in controls and establish database connections.
Control events:
 Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.

LoadComplete:
Use this event for tasks that require that all other controls on the page be loaded.
PreRender:
This is the last event raised before the HTML code is generated for the page. The PreRender event also occurs for each control on the page. Use the event to make final changes to the contents of the page or its controls.
SaveStateComplete:
Before this event occurs, ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored.
Use this event to perform tasks that require view state to be saved, but that do not make any changes to controls.
Render:
This is the stage where the HTML code for the page is rendered. The Page object calls the Render method of each control at this stage. All ASP.NET Web server controls have a Render method that writes out the control's markup that is sent to the browser.
UnLoad:
This event occurs for each control and then for the page. In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.

Friday 20 December 2013

OOPs Concept Example


Abstract and Virtual:
If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated.
Whatever functionality in common to the entire system which functionality put together and keep into separate.


Why do we need Abstract class:

Take three classes Human, Man and Woman. All Man and Woman belong to Human category. In Original object exists for only for Man or Woman. NO object exists for Human category. But both Man and Woman have common characteristics where we can say it as Human characters. Now you can understand that why do we need abstract class.


Abstract Rules
-> We cannot create object for abstract class
-> we cannot declare the abstract method in non abstract class
-> we cannot declare the non abstract method or virtual method without declare the body
-> We cannot declare a body in abstract method
-> When at least one of the methods in the class is abstract.
-> Abstract can extend only one abstract class.
->An abstract class can extend c# class only
Difference between Abstract and Virtual

Abstract
Virtual
No Keyword
Can have implementation? 
No
Yes
Yes
Can override?
Must
Can but not a must
You can declare a new method with the same name
Which keyword to use to provide new implementation in the concrete class?
override
override
No keyword needed
If an object is created of thebase class type, which method will be executed?
Concrete implementation
The parent implementation will be called only if no implementation is provided in the concrete class
Parent implementation
If an object is created of the concrete class type, which method will be executed?
Concrete implementation
Concrete implementation
The parent implementation will be called only if no implementation is provided in the concrete class
Interface

Interface nothing but skeleton of the class
We cant create object for interface
It s a Pure abstraction
Pure abstraction means you cannot have concrete methods
Interfaces should not have any concrete methods, it should only have method declarations.
A method with definition is concrete method

In which scenario we use Interfaces:

If your child classes should all implement a certain group of methods/functionalities but each of the child classes is free to provide its own implementation then use interfaces. 
For e.g. if you are implementing a class hierarchy for vehicles implement an interface called Vehicle which has properties like Color MaxSpeed etc. and methods like Drive(). All child classes like Car Scooter Airplane Solar Car etc. should derive from this base interface but provide a separate implementation of the methods and properties exposed by Vehicle
Which one is advantage over another:

Interface has advantage over Abstract class. Since you can not use abstract class for already inherited class. But you can use interface for already inherited class.

Difference between Abstract and Interface:

Interface
Abstract
1.A class can implement multiple interface
2.An interface can extend another interface
3.Interface contain only method and propertied . (can t declare variables)
4.EX:
Public interface
{
 Void accelerator();
String engine{
Get;
Set;
}
}
5.I can say that interface is for "PURE ABSTRACTION". Pure abstraction means  you can not have concrete methods. A method with definition is Concrete method.
1.Abstract can extend only one abstract class.
2.An abstract class can extend c# class only
3.It contains private member also we can put some methods with implementation.
4.Ex:
Public abstract class vehicles
{
 Private intnoofwheels;
 Private string color;
 Public abstract string engine
 {
 Get;
 Set;
 }
Public abstract void accelerator();
}
5.   But abstract class can have concrete methods.


We declared 10 methods in interface, now we should implement all 10 methods. But we want implement 2 methods only.
How?
Example.

Sealed Class:

Sealed classes are used to restrict the inheritance feature of object oriented programming
A sealed class cannot be used as a base class.
Sealing a class means one cannot derive from it.
A method means one cannot override it. 
Example.
Polymorphism
Polymorphism means many forms.
Polymorphism is the ability to process objects differently depending on their data types.
Polymorphism is the ability to redefine methods for derived classes.

Polymorphism provides following features: 
It allows you to invoke methods of derived class through base class reference during runtime.
It has the ability for classes to provide different implementations of methods that are called through the same name.

Polymorphism

Polymorphism is of two types: 
1.Compile time polymorphism/Overloading
2.Runtime polymorphism/Overriding
Compile Time Polymorphism
 Compile time polymorphism is method overloading. It is also called early binding.
 In method overloading method performs the different task at the different input parameters.
Runtime Time Polymorphism
 Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding

Overloading:
Overloading a method simply involves having another method with the same prototype.
Overriding
To change the behavior of the method for the derived class
Note
Method overloading has nothing to do with inheritance or virtual methods.
Following are examples of methods having different overloads:
void area(int side);
void area(int l, int b);
Void area(int l, double b, int c)
Void area(double b, int l, int c)
void area(float radius);
Polymorphism

When and why to use method overloading
 
Use method overloading in situation where you want a class to be able to do something, but there is more than one possibility for what information is supplied to the method that carries out the task.
 
You should consider overloading a method when you for some reason need a couple of methods that take different parameters, but conceptually do the same thing.
Example
Void Area(int a)  //Square
Void Area(int h,int w)  //Rectangle
Void Area(int a, int l, int w)  //Cylinder
Void Area(int  pi, int r , int l)  //Cone
Void Area(int  pi, int r )  //Circle

When and why to use method overriding
Its obvious that when we do inheritance between two classes, all the methods and properties of the first class are derived to the other class so that this becomes the child class which  adobes all the functionality of base class. It can also possesses its own separate methods.
But there is a big problem in inheriting the second class to the first class as it adobes all the methods same as the base class has, which  means that after inheritance both(base class& child class) have the methods of same name and same body as shown in this example
Example,
 we have seen example of overriding

how many overload of a method we can have?
What?
Type?
When?
Overloading?
Overriding?
static binding?
Late binding?

String and String Builder:
Strings are Immutable (Not Modifiable). If you try to modify the string it actually creates a new string and the old string will be then ready for garbage collection.
String Builder when instantiated, creates a new string with predefined capacity and up to that capacity it can accommodate string without needing to create a new memory location for the string....i mean it is modifiable and can also grow as and when needed. 
The most common operation with a string is concatenation. This activity has to be performed very efficiently. When we use the "String" object to concatenate two strings, the first string is combined to the other string by creating a, and then the old string is deleted. This process is a little long. Hence we say "Strings are immutable".
When we make use of the "String Builder" object, the Append method is used. This means, an insertion is done on the existing string. Operation on String Builder object is faster than String operations, as the copy is done to the same location. Usage of String Builder is more efficient incase large amounts of string manipulations have to be performed.
String Example:
   String myString=”Welcome”;
  myString=myString+”Software Team”;
String builder Example
    StringBuilder sb = new StringBuilder();
        sb.Append("raj");
        sb.Append("mani");

String builder
Methods:
Ex:
    Append, insert, remove, replace and Tostring.
Performance:
1.Avoid short appends.
2.Cache objects.
3.Avoid some data types.
4.Data Types
5.Append Chars
6.Stringbuilder Comparison
7.Append integers
8.Capacity
9.Example:
  http://www.dotnetperls.com/stringbuilder


Override: When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class.
New: If you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it.
If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).
Override: used with virtual/abstract/override type of method in base class
New: when base class has not declared method as virtual/abstract/override

Static class , method  and variables

12 Features of Static class
1.A static class cannot be instantiated
2.Static class can have only static members.
3.Member of the Static class can be accessed by class name itself.
4.Static class is sealed. So static class cannot be inherited.
5.Static class contains only static constructors.
6.Static class cannot have instance constructors.
7.Static class can only be inherited only from object class.
8.Static class is preceded by keyword static.
9.Static constructor of static class called only once.
10.Static class has private constructors
11.Static classes cannot implement interfaces
12.static classes cannot have instance constructors
Notable Points here are:
A static method can be invoked directly from the class level
A static method not requires any class object
Any main() method is shared through entire class scope so it always appears with static keyword.
Static method
A static method can access only static fields.
A static method cannot access non static fields.
A static method cannot be called using object of a class
A static method can be called using class name.
Static field can be used using class name.
Static method cannot be override or overload.
We can't put access modifier in static constructor?
Constructor:
http://www.programcall.com/16/csnet/constructor-types-with-example-programs-in-csnet.aspx

A static constructor does not take access modifiers or have parameters.
A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
A static constructor cannot be called directly.
The user has no control on when the static constructor is executed in the program.
A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.
Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
If a static constructor throws an exception, the runtime will not invoke it a second time, and the type will remain uninitialized for the lifetime of the application domain in which your program is running.
http://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx
what is difference between instance constructor and Static constructor in C#.Net


Main Differences are :
 A Constructor declare using Static modifier was known as  Static Constructor. Rest of all were Instance Constructor.
Static Constructor are responsible for initialization of static variables and Instance Constructor for initialization of instance constructor.
A static constructor is called only one's in the execution of a class. Where as instance constructor gets called each time we create the object of the class. if no object is created. It is not called at all.
static constructor is the first block of which gets executed under the class.
A static constructor can't be parameterized because explicit calling of the constructor is not done.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1{
    class staticconstructor
    {
        static staticconstructor()
        {
            Console.WriteLine("static constructor");
        }
         staticconstructor()        {
            Console.WriteLine("non-static constructor");
        }
        static void Main()
        {
            Console.WriteLine("main method");
            staticconstructor st = new staticconstructor();
            staticconstructor st1 = new staticconstructor();
            Console.ReadLine();
        }
    }
}     o/p: static constructor, main method  , non-static constructor , non-static constructor

Notable Points here are:
A static method can be invoked directly from the class level
A static method not requires any class object
Any main() method is shared through entire class scope so it always appears with static keyword.
Static method
A static method can access only static fields.
A static method cannot access non static fields.
A static method cannot be called using object of a class
A static method can be called using class name.
Static field can be used using class name.
Static method cannot be override.
We can't put access modifier in static constructor?


You can get the reference to the page via HttpContext.CurrentHandler.
public static string GetData(int CustomerID) {
   Page pageHttpContext.Current.Handler as Page;
   if (page != null)
   {
      string outputToReturn = "";
      page.ViewState["MyVal"]="Hello";
      return outputToReturn;
      //btw, what a strange method!
   }
}

collection

Four important categories
Index based
Array
List
Key value pair
Hash table
Sort list
Prioritized collection
Queue
Stack
Specialized collection
String collection
Hybrid dictionary





array and array list

Array
Array List
1.System namespace
2.Char[] vowel=new char[];
3.Capacity of an array is fixed
4.It collection of same data type
5.Array can have multiple dimensions
6.Ex:
1.System.collection namespace
2.Arraylist list =new arraylist()
3.Array list can increase and decrease size dynamically
4.It can hold different data type
5.Array list can have one dimension.
6.Ex:

Hash Table and Array List
Hash Table
Array List
1.It is a dictionary
2.It is both index and key based
3.Hash table is a map
4.Here we can add data with key
5.Retrieving by key in hash table is faster than t\retrieving by array list
1.Collection of data
2.Index based
3.It is a list
4.We can only add items to the list
5.Here we can add any data type value, every item in array list is treated as object.
hash table

HashTable:
   HashTable stores a key-value pair type collection of data. 
NOTE:

Both key and value are object 
  the key values are UNIQUE 
Functions:
Clear
Remove
Containskey
Containsvalue
Contains
Add
Variables
Count

Remove:

hash_table_name.Remove(key);
Remove All Values:

hash_table_name.Clear()

ContainsKey(Key)

its returns true or false.. 
ContainsValue(value): 
  its returns true or false.. 
EXAMPLE 

Hashtable sampleHt  = New Hashtable
sampleHt.add("US",”united States”)  // Area- key.  1000 - value
sampleHt.add("IND",”India”) 
        // To fetch the value we can use name, for example
        String countryname=convert.tostring(sampleHt[“US”]);
         sampleHt.remove(“US”);
         IDictionaryEnumerator  idic= sampleHt.GetEnumerator();
                    while(idic.MoveNext())
                    {
                        idic.Value.ToString();
                    }
 











Example 1:
// We cannot crate object for abstract class

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   public abstract class AbstactClass
    {
       public abstract string GetAbstractValue();
    }
    public class main1
    {
        static void Main(string[] args)
        {
            AbstactClass absObj = new AbstactClass();
          
        }
    }
}

Error  1      Cannot create an instance of the abstract class or interface 'ConsoleApplication1.AbstactClass'
Example 2:
// we cannot declare the abstract method in non abstract class

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   public class AbstactClass
    {
       public abstract string GetAbstractValue();
    }
    public class main1
    {
        static void Main(string[] args)
        {
            AbstactClass absObj = new AbstactClass();
          
        }
    }
}

Error:
'ConsoleApplication1.AbstactClass.GetAbstractValue()' is abstract but it is contained in non-abstract class 'ConsoleApplication1.AbstactClass'






Example 2:
// we cannot declare the non abstract method without definition

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   public abstract class AbstactClass
    {
       public abstract void GetAbstractValue();
       public  void GetValue();

//       public  void GetValue(); // don’t throw error

//{}
      
    }
   public class Test : AbstactClass
   {
       public override void GetAbstractValue()
       {
       }
   }
    public class main1
    {
        static void Main(string[] args)
        {
            Test absObj = new Test();
            absObj.GetAbstractValue();
          
        }
    }
}


// We cannot declare a body in abstract method

public abstract class AbstactClass
    {
       public abstract void GetAbstractValue()
       {

       }
       public void GetValue()
       {
           Console.WriteLine("Get abstract method");
       }
        
      
    }




// Abstract, virtual method 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public abstract class BaseClass
    {
        public abstract string GetAbstractValue();

        public virtual string GetVirtualValue()
        {
            return "Base GetVirtualValue";
        }

        public string GetValue()
        {
            return "Base GetValue";
        }
    }
    public class SubClass : BaseClass
    {
        public override string GetAbstractValue()
        {
            return "Sub Get Abstract Value";
        }
        public override string GetVirtualValue()
        {
            return "Sub GetVirtualValue";
        }
        public string GetValue() //new
        {
            return "Concrete GetValue";
        }
    }
    class Test
    {
        static void Main(string[] args)
        {
            BaseClass instance1 = new SubClass();
            Console.WriteLine(instance1.GetAbstractValue());
            Console.WriteLine(instance1.GetVirtualValue());
            Console.WriteLine(instance1.GetValue());

            SubClass instance2 = new SubClass();
            Console.WriteLine(instance2.GetAbstractValue());
            Console.WriteLine(instance2.GetVirtualValue());
            Console.WriteLine(instance2.GetValue());

            Console.Read();
        }
    }
}


//Since you cannot use abstract class for already inherited class. But you can use interface for already inherited class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public interface inrefacename
    {
        void somemethod();

    }
  
    public abstract class BaseClass
    {
        public abstract string GetAbstractValue();

        public virtual string GetVirtualValue()
        {
            return "Base GetVirtualValue";
        }

        public string GetValue()
        {
            return "Base GetValue";
        }
    }
   public class classtest
    {

        public string GetValue1()
        {
            return "Base GetValue";
        }
    }
   public class classtest1 : classtest, inrefacename  // baseclass – abstract class (will not use abstract class)
   {

       public string GetValue4()
       {
           return "Base GetValue";
       }
      public  void somemethod()
       {
           Console.WriteLine("somemethod");
       }
   }
   public class SubClass : BaseClass
    {
        public override string GetAbstractValue()
        {
            return "Sub Get Abstract Value";
        }
        public override string GetVirtualValue()
        {
            return "Sub GetVirtualValue";
        }
        public  string GetValue()  //new
        {
            return "Concrete GetValue";
        }
    }
    class Test
    {
        static void Main(string[] args)
        {
            BaseClass instance1 = new SubClass();
            Console.WriteLine(instance1.GetAbstractValue());
            Console.WriteLine(instance1.GetVirtualValue());
            Console.WriteLine(instance1.GetValue());

            SubClass instance2 = new SubClass();
            Console.WriteLine(instance2.GetAbstractValue());
            Console.WriteLine(instance2.GetVirtualValue());
            Console.WriteLine(instance2.GetValue());

            Console.Read();
        }
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public interface IMyInterface
    {
        void SomeMethod();
        void SomeOtherMethod();
    }
    public abstract class MyClass : IMyInterface
    {
        // Really implementing this
        public void SomeMethod()
        {
            // ...
        }

        // Derived class must implement this
        public abstract void SomeOtherMethod();
    }
    class Test
    {
        static void Main(string[] args)
        {

            Console.Read();
        }
    }
}



// Achieve multiple inheritance concept via interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public interface IA1
    {
        void m2();
        void m();

    }

    public interface IA2
    {
        void m2();
    }

    public class CA : IA1, IA2
    {
        public void m()
        {
        }

        public void m2()
        {
            Console.WriteLine("A");
        }
    }
    public class CA1 : CA
    {
        public void m()
        {
        }

        public void m2()
        {
            Console.WriteLine("B");
        }
    }
    public class main1
    {
        static void Main(string[] args)
        {
            CA c1 = new CA();
            c1.m();
            c1.m2();
            CA1 ca1 = new CA1();
            ca1.m();
            ca1.m2();
            Console.Read();
        }
    }
}

// Dynamic Binding (hiding)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class A
    {
        public virtual void WhoAreYou() { Console.WriteLine("I am an A"); }
        public virtual void WhoAreYou1() { Console.WriteLine("I am an A1"); }
        public virtual void WhoAreYou2() { Console.WriteLine("I am an A2"); }
    }
    class B : A
    {
        public override void WhoAreYou() { Console.WriteLine("I am a B"); }
    }
    class C : B
    {
        public new virtual void WhoAreYou() { Console.WriteLine("I am a C"); }
        //  public override void WhoAreYou1() { Console.WriteLine("I am an C1"); }
        public override void WhoAreYou2() { Console.WriteLine("I am an C2"); }

    }
    class D : C
    {
        public override void WhoAreYou() { Console.WriteLine("I am a D"); }
        public override void WhoAreYou2() { Console.WriteLine("I am an D2"); }
    }


    class Test
    {
        static void Main(string[] args)
        {

            C c = new D();  // where to extend C class in D
            c.WhoAreYou();// "I am a D"
            A a = new D();    // where to extend A class in B
            a.WhoAreYou();// "I am a B"

            A a1 = new D();  // No extend - virtual method
            a1.WhoAreYou1(); // "I am a A1"

            B a2 = new C();  // where to extend b class in c
            a2.WhoAreYou2(); // "I am a C2"

            B a3 = new D(); // where to extend b class in c
            a3.WhoAreYou2(); // "I am a D2"

            Console.ReadLine();

        }
    }

}


Sealed Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public sealed class classsealed
    {
        public string ID;
        public double Price;
        public string GetValue()
        {
            return "Sealed class";
        }
    }
    //public class subsealedclasss : classsealed
    //{
    //    public string subsealedmethod()
    //    {
    //        return "subSealed class";
    //    }

    //}
    class Test
    {
        static void Main(string[] args)
        {
            classsealed sealedobject = new classsealed();
            Console.WriteLine(sealedobject.GetValue());
            sealedobject.ID = "10";
            sealedobject.Price = 12.23;
            //subsealedclassssubsealedobject = new subsealedclasss();
            //subsealedobject.subsealedmethod();
            Console.Read();


        }
    }

}

// Static Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public static class staticclass   // : object //7. Static class can only be inherited only from object class
    {
        // int a; // 2.    Static class can have only static members.
        static int i=1; // access
        //public void method()  // Static class can have only static method.
        //{
        //    Console.WriteLine("Test method");
        //}
        public static void method1()
        {
            Console.WriteLine("Test static method");
            Console.WriteLine(i);
        }
        //staticclass()  // static classess cannot have instance constructors
        //{
       //  Console.WriteLine("instance constructor");
        //}
        static staticclass()
        {
            Console.WriteLine("static constructor");
        }


    }
    public class Bus
    {
        // Static constructor:
        static Bus()
        {
            System.Console.WriteLine("The static constructor invoked.");
        }

     
        public static void Drive()
        {
            System.Console.WriteLine("The Drive method invoked.");
        }
    }

    //public class Testclass : staticclass   // 4.     Static class is sealed. So static class cannot be inherited
    //{
    //}
    class Test
    {
        static void Main(string[] args)
        {
            //   staticclass obj = new staticclass();  // static class cannot be instantiated
            staticclass.method1(); // first constructor only executed
            //staticclass.i = 6;
          
            Bus.Drive();
            Console.ReadLine();
        }
    }
}





// static method
public class Bus
{
    // Static constructor:
    static Bus()
    {
        System.Console.WriteLine("The static constructor invoked.");
    }

    public static void Drive()
    {
        System.Console.WriteLine("The Drive method invoked.");
    }
}

class TestBus
{
    static void Main()
    {
        Bus.Drive();
    }
}
// A static constructor is called automatically to initialize and first called

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
  
        class Program
        {

            static void Main(string[] args)
            {
                Child t = new Child();
            }
        }

        class Parent
        {
            public Parent()
            {
                Console.WriteLine("Parent Instance Constructor");
                Console.ReadKey();
            }

            static Parent()
            {
                Console.WriteLine("Parent Static Constructor");
                Console.ReadKey();
            }
        }
        class Child : Parent
        {
            public Child()
            {
                Console.WriteLine("Child Instance Constructor");
                Console.ReadKey();
            }

            static Child()
            {
                Console.WriteLine("Child Static Constructor");
                Console.ReadKey();
            }
        }
   
}


Output:
Child Static Constructor
Parent Static Constructor
Parent Instance Constructor
Child Instance Constructor



// Hash table

HashTable:
HashTable stores a key-value pair type collection of data. 
NOTE: 

Both key and value are object 
the key values are UNIQUE 
Functions:
1.     Clear
2.     Remove
3.     Containskey
4.     Containsvalue
5.     Contains
6.     Add
Variables
1.     Count

Remove: 

hash_table_name.Remove(key);
Remove All Values: 

hash_table_name.Clear()
ContainsKey(Key) 


its returns true or false.. 
ContainsValue(value): 
EXAMPLE 
Hashtable sampleHt  = New Hashtable 
sampleHt.add("US",”united States”)  // Area- key.  1000 - value
sampleHt.add("IND",”India”) 
// To fetch the value we can use name, for example
String countryname=convert.tostring(sampleHt[“US”]);
sampleHt.remove(“US”);
IDictionaryEnumerator  idic= sampleHt.GetEnumerator();
                    while(idic.MoveNext())
                    {
                        idic.Value.ToString();
                    }










// Why c# not support multiple inheritance?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class A
    {
        protected void samplemethod();
    }
    class B
    {
        protected void samplemethod();

    }
    class C : A, B
    {
    }
    class Test
    {
        static void Main(string[] args)
        {
            C obj = new C();
            obj.samplemethod(); // here which method to call now A or B?
        }
    }
}







Interface with objects:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public interface IMyInterface
    {
        void SomeMethod();
        void SomeOtherMethod();
    }
    public class MyClass : IMyInterface
    {
        // Really implementing this
        public void SomeMethod()
        {
            Console.WriteLine("Interface object");
        }

        // Derived class must implement this
        public void SomeOtherMethod()
        {
        }
    }
    class Test
    {
        static void Main(string[] args)
        {
            IMyInterface obj = new MyClass();
            obj.SomeMethod();
           

            Console.ReadLine();

        }
    }

}