Translate

Wednesday, August 29, 2012

What is the difference between user and custom controls?


User controls are easier to create whereas custom controls require extra effort.
User controls are used when the layout is static whereas custom controls are used in dynamic layouts.
A user control cannot be added to the toolbox whereas a custom control can be.
A separate copy of a user control is required in every application that uses it whereas since custom controls are stored in the GAC, only a single copy can be used by all applications.

Why don’t we have multiple inheritance in .NET?


There are several reasons for this. In simple words, the efforts are more, benefits are less. Different languages have different implementation requirements of multiple inheritance. So in order to implement multiple inheritance, we need to study the implementation aspects of all the languages that are CLR compliant and then implement a common methodology of implementing it. This is too much of efforts. Moreover multiple interface inheritance very much covers the benefits that multiple inheritance has.

HttpContext


HttpContext object will hold information about the current http request. HttpContext object will be constructed newly for every request given to an ASP.Net application and this object will hold current request specific informations like Request, Response, Server, Session, Cache, User and etc. For every request, a new HttpContext object will be created which the ASP.Net runtime will use during the request processing. A new HttpContext object will be created at the beginning of a request and destroyed when the request is completed.
One of the best features of HttpContext object is using its Item Collection.

Array


An array is a fixed collection of same-type data that are stored contiguously.
Arrays are declared much like variables, with a set of [] brackets after the data type, like this: 

You need to instantiate the array to use it, which is done like this: 

string[] names = new string[2];

Differrence between Array.CopyTo() and Array.Clone()

Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single Dimension arrays.

Clone() method makes a clone of the original array. It returns an exact length array.

CopyTo()
 copies the elements from the original array to the destination array starting at the specified destination array index. Note that, this adds elements to an already existing array.

Difference between delete and truncate in sql server?

TruncateDelete
TRUNCATE is a DDL commandDELETE is a DML command
TRUNCATE TABLE always locks the table and page but not each rowDELETE statement is executed using a row lock,                                             each row in the table is locked for deletion
Cannot use Where ConditionWe can specify filters in where clause
It Removes all the dataIt deletes specified data if where condition exists.
TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.Delete activates a trigger because the operation                                are logged individually.
Faster in performance wise, because it is minimally logged in transaction log.Slower than truncate because, it maintain logs for every record
 Drop all object’s statistics and marks like High Water Mark free extents and leave the object really empty with the first extent. zero pages are left in the tablekeeps object’s statistics and all allocated space. After a                       DELETE statement is executed,the table can still contain empty pages.
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and records only the page deallocations in the transaction loThe DELETE statement removes rows one at a time                       and records an entry in the transaction log for each deleted row
If the table contains an identity column, the counter for that column is reset to the seed value that is defined for the columnDELETE retain the identity
Restrictions on using Truncate Statement
1. Are referenced by a FOREIGN KEY constraint.
2. Participate in an indexed view.
3. Are published by using transactional replication or merge replication.
Delete works at row level, thus row level constrains apply

What is the difference between stored procedure and function.

1) Stored procedure are compiled for first time and compiled format is saved and executes compiled code when ever it is called. But function is compiled and executed every time it is called. 

2) Function must return a value but in stored procedure it is optional. 

3) Function takes one input parameter it is mandatory but stored procedure may take o to n input parameters.

4) Functions can be called from select statement, but stored procedures can not be called from select statement. 

5) We can use try catch statements in stored procedures but in functions we can not use.

6) We can not use insert,delete,update and create statements in functions but in stored procedures we can use those statements. 

7 ) Functions can have only input parameters but stored procedure can have input and out put parameters

What is Singleton ?


Singleton class is a class whose only one object can be created at a time
Singleton provides a global, single instance by:

·  Making the class create a single instance of itself.

·  Allowing other objects to access this instance through a class method that returns a reference to the instance. A class method is globally accessible.

·   Declaring the class constructor as private so that no other object can create a new instance.

Singleton results in the following benefits and liabilities:

               Benefits

·   Instance control. Singleton prevents other objects from instantiating their own copies of the Singleton object, ensuring that all objects access the single instance.

·   Flexibility. Because the class controls the instantiation process, the class has the flexibility to change the instantiation process.

Liabilities

·   Overhead. Although the amount is minuscule, there is some overhead involved in checking whether an instance of the class already exists every time an object requests a reference. This problem can be overcome by using static initialization as described in Implementing Singleton in C#.

·   Possible development confusion. When using a singleton object (especially one defined in a class library), developers must remember that they cannot use the new keyword to instantiate the object. Because application developers may not have access to the library source code, they may be surprised to find that they cannot instantiate this class directly.

·   Object lifetime. Singleton does not address the issue of deleting the single object. In languages that provide memory management (for example, languages based on the .NET Framework), only the Singleton class could cause the instance to be deallocated because it holds a private reference to the instance. In languages, such as C++, other classes could delete the object instance, but doing so would lead to a dangling reference inside the Singleton class.

What is Indexer ?


Indexer : Indexers allow your class to be used just like an array.
·         Indexer Concept is object act as an array.
Indexer an object to be indexed in the same way as an array.
·         Indexer modifier can be private, public, protected or internal.
·         The return type can be any valid C# types.
·         Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.

this [Parameter]
{
    get
    {
        // Get codes goes here
    }
    set
    {
        // Set codes goes here
    }

For Example:

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

namespace Indexers
{
    class ParentClass
    {
        private string[] range = new string[5];
        public string this[int indexrange]
        {
            get
            {
                return range[indexrange];
            }
            set
            {
                range[indexrange] = value;
            }
        }
    }

    /* The Above Class just act as array declaration using this pointer */

    class childclass
    {
        public static void Main()
        {
            ParentClass obj = new ParentClass();

            /* The Above Class ParentClass  create one object name is obj */

            obj[0] = "ONE";
            obj[1] = "TWO";
            obj[2] = "THREE";
            obj[3] = "FOUR ";
            obj[4] = "FIVE";
            Console.WriteLine("WELCOME TO C# CORNER HOME PAGE\n");
            Console.WriteLine("\n");

            Console.WriteLine("{0}\n,{1}\n,{2}\n,{3}\n,{4}\n", obj[0], obj[1], obj[2], obj[3], obj[4]);
            Console.WriteLine("\n");
            Console.WriteLine("ALS.Senthur Ganesh Ram Kumar\n");
            Console.WriteLine("\n");
            Console.ReadLine();
        }
    }
}

Why we use property in c#? (get, set)


Properties are a way to control access to your private members. It simply (set) copies the given value to the private member and (get) returns the private member without modifying it. Often, the set part is used to check the given value in order to avoid later errors, or to simplify code

private string myString = "";

public string MyString
{
set
{ if ( value == null )
{value = "";}
myString = value;
}
}

Document Object Model (DOM)


The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents
The DOM is separated into 3 different parts / levels:


  • Core DOM - standard model for any structured document
  • XML DOM - standard model for XML documents
  • HTML DOM - standard model for HTML documents
What is the XML DOM?
  • A standard object model for HTML
  • A standard programming interface for HTML
  • Platform- and language-independent
  • A W3C standard
All XML Elements Must Have a Closing TagXML Tags are Case SensitiveXML Elements Must be Properly NestedXML Documents Must Have a Root Element
    .....
  • The entire document is a document node
  • Every HTML element is an element node
  • The text in the HTML elements are text nodes
  • Every HTML attribute is an attribute node
  • Comments are comment nodes
DOM Example                    DOM Lesson one     Hello world!   The HTML DOM Node Tree
  • x.innerHTML - the text value of x
  • x.nodeName - the name of x
  • x.nodeValue - the value of x
  • x.parentNode - the parent node of x
  • x.childNodes - the child nodes of x
  • x.attributes - the attributes nodes of x

  • x.getElementById(id) - get the element with a specified id
  • x.getElementsByTagName(name) - get all elements with a specified tag name
  • x.appendChild(node) - insert a child node to x
  • x.removeChild(node) - remove a child node from x


The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them.
What is the HTML DOM?
The HTML DOM is:
The HTML DOM defines the objects and properties of all HTML elements, and the methods(interface) to access them.

 

DOM Nodes
According to the DOM, everything in an HTML document is a node.
The DOM says:
Look at the following HTML document:


The HTML DOM views an HTML document as a tree-structure. The tree structure is called a node-tree.
All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created.

The programming interface of the DOM is defined by standard properties and methods.
Properties are often referred to as something that is (i.e. the name of a node).
Methods are often referred to as something that is done (i.e. remove a node).

HTML DOM Properties
Some DOM properties:
Note: In the list above, x is a node object (HTML element).

HTML DOM Methods
Some DOM methods:
Note: In the list above, x is a node object (HTML element).

What is the difference between Finalize() and Dispose()?


Dispose() is called by as an indication for an object to release any unmanaged resources it has held. 
Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object. 
Dispose() operates determinalistically due to which it is generally preferred.

What is N-tire Architecture ?


The n-Tier application has three tiers or layers; they are called the presentation layer, the business layer and the data layer. Each layer interacts with the layer directly below, and has specific function to perform. The presentation layer is responsible for displaying the user interface to the end user. The programmer uses this layer for designing the user interface and to transfer data. In ASP.NET, ASPX pages, user controls, server controls and sometimes security related classes and objects are used to support the presentation layer.
The business layer works as a go-between to transfer the data from presentation layer. In the three-tier architecture, the data access layer does not interact directly with the presentation layer. The architecture in ASP.NET includes using SqlClient or OleDb objects to retrieve, update and delete data from SQL Server or other databases and passing the data retrieved to the presentation layer in a DataReader or DataSet object, or a custom collection object. The data layer gets the data from the business layer and sends it to the database or vice versa.

The main advantage of using n-Tier is that the complexity associated with the business and the process is reduced and is easy to implement. The elements of performance, scalability and future development issues need to be considered when deciding on the architecture of the application.

What is X-Path?

XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document.

XPath is a language for finding information in an XML document.

What is the meaning of XBRL??


XBRL (Extensible Business Reporting Language) is an XML-based computer language for the electronic transmission of business and financial data. The goal of XBRL is to standardize the automation of business intelligence (BI).
XBRL is an open standard which is overseen by a not-for-profit organization called XBRL International. XBRL uses tags to describe and identify each item of data in an electronic document. The tags allow computer programs to sort through data and analyze relationships quickly and generate output in various formats. Because the tags are standardized, analysis can be conducted across multiple documents from multiple sources, even if the text in the documents is written in different languages.

Difference between CDATA and PCDATA in XML ?


PCDATA - Parsed Character Data :
 

XML parsers normally parse all the text in an XML document.
PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded. 
CDATA - (Unparsed) Character Data :
The term CDATA is used about text data that should not be parsed by the XML parser.Characters like "<" and "&" are illegal in XML elements.
CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.

Differences Between XML and HTML

XML :

XML was designed to describe data and to focus on what data is.XML tags are not predefined.XML is case sensitive.
XML makes it mandatory for the user the close each tag that has been used.

HTML :

HTML was designed to display data and to focus on how data looks .
HTML tags are predefined
HTML is not case sensitive
HTML is not strict if the user does not use the closing tags