Thursday, October 6, 2011

Microsoft Technologies


Basics:
1) .NET:

     .NET is a framework. It includes a large library and supports several programming languages which allows language interoperability.


2)ADO.NET:
   
     It stands for ActiveX Data Object. ADO.NET provides consistent access to data sources such as MS-SQL Server, as well as data sources exposed through OLE DB and XML.


3)What is Interface?
      
      An interface only contains the signatures of methods, delegates or events.  The implementation of the methods is done in the class.


4)What is Delegates?

        A delegate is a type that reference a method.  Once a delegate is assigned a method, it behaves exactly like that method.  A delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++.


5)What is a IL?
 
        (IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL(Common Intermediate Language). All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.


6)What is a CLR?
 
        Full form of CLR is Common Language Runtime and it forms the heart of the .NET framework. All Languages have runtime and its the responsibility of the runtime to take care of the code execution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.DLL, Java has Java Virtual Machine etc.


7)What is Abstract Class?

        The abstract keyword enables you to create class and class members that are incomplete and must be implemented in a derived class.
Code:

          public abstract class A
          {
             //Class members here.
          }
        The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.


8)Abstract Class Features:

            *An Abstract class cannot be instantiated.
            *An Abstract class may contain abstract methods and accessors.
          *It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited.
        *A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.

9)Abstract Method Features:

         *An abstract method is implicitly a virtual method.
         *Abstract method declarations are only permitted in abstract class.
         *Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no braces() following the signature.

10)Difference between VB.NET and C#.NET?

VB.NET:
              *Support Optional parameters which makes COM interoperability much easy.
              *Has the WITH construct.
              *No Operator Overloading.
              *No 'this' statement.
              *Cannot access the unmanaged code.

C#.NET:
              *XML documentation is generated from Source code.
              *No WITH construct.
              *Operator Overloading is possible.
              *Use of 'this' statement makes unmanaged resource disposal simple.
              *Can access the unmanaged code.

11)Partial Class Definiton:
        
            It is possible to split the definition of a class or a struct or an interface over two or more source files.


12)How many Directives in ASP.NET?
                    *@Assembly
                    *@Control
                    *@Implements
                    *@Import
                    *@Master
                    *@MasterType
                    *@OutputCache
                    *@Page
                    *@PreviousPageType
                    *@Reference
                    *@Register

13)How to get the url of the current page in C#?
     => string url=HttpContext.Current.Request.Url.AbsoluteUri;  -  it is used to get the full url.


     => string path=HttpContext.Current.Request.Url.AbsolutePath;  -  it is used to get the path in the server.


     => string host=HttpContext.Current.Request.Url.Host;  -  it is used to get the host that page is running.

14)Session:
     Sessions can be used to store even complex data for the user just like cookies. Actually, sessions will use cookies to store the data, unless you explicitly tell it not to. Sessions can be used easily in ASP.NET with the Session object. We will re-use the cookie example, and use sessions instead. Keep in mind though, that sessions will expire after a certain amount of minutes, as configured in the web.config file. Markup code:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Sessionstitle>
head>
<body runat="server" id="BodyTag">
    <form id="form1" runat="server">
    <asp:DropDownList runat="server" id="ColorSelector" autopostback="true" onselectedindexchanged="ColorSelector_IndexChanged">
        <asp:ListItem value="White" selected="True">Select color...asp:ListItem>
        <asp:ListItem value="Red">Redasp:ListItem>
        <asp:ListItem value="Green">Greenasp:ListItem>
        <asp:ListItem value="Blue">Blueasp:ListItem>
    asp:DropDownList>
    form>
body>
html>
And here is the CodeBehind:
using System;
using System.Data;
using System.Web;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["BackgroundColor"] != null)
        {
            ColorSelector.SelectedValue = Session["BackgroundColor"].ToString();
            BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
        }
    }

    protected void ColorSelector_IndexChanged(object sender, EventArgs e)
    {
        BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
        Session["BackgroundColor"] = ColorSelector.SelectedValue;
    }
}
As you can see, the example doesn't need a lot of changes to use sessions instead of cookies. Please notice that session values are tied to an instance of your browser. If you close down the browser, the saved value(s) will usually be "lost". Also, if the webserver recycles the aspnet_wp.exe process, sessions are lost, since they are saved in memory as well. This can be avoided by saving session states on a separate StateServer or by saving to a SQL server, but that's beyond the scope of this article.