Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Wednesday, 26 December 2012

Convert & Parse methods

Convert & Parse methods

There are two groups of methods, which aid us at converting values.
using System;

class CSharpApp
{
    static void Main()
    {
        Console.WriteLine(Convert.ToBoolean(0.3));
        Console.WriteLine(Convert.ToBoolean(3));
        Console.WriteLine(Convert.ToBoolean(0));
        Console.WriteLine(Convert.ToBoolean(-1));

        Console.WriteLine(Convert.ToInt32("452"));
        Console.WriteLine(Convert.ToInt32(34.5));
    }
}
The Convert class has many methods for converting values. We use two of them.
Console.WriteLine(Convert.ToBoolean(0.3));
We convert a double value to a bool value.
Console.WriteLine(Convert.ToInt32("452"));
And here we convert a string to int.

using System;

class CSharpApp
{
    static void Main()
    {
        Console.WriteLine(Int32.Parse("34"));
        Console.WriteLine(Int32.Parse("-34"));
        Console.WriteLine(Int32.Parse("+34"));
    }
}
Converting strings to integers is a very common task. Often when we bring values from databases or GUI widgets.
Console.WriteLine(Int32.Parse("34"));
We use the Parse() method of the Int32 class to convert a string to int value.

Nullable types

Nullable types

Value types cannot be assigned a null literal. Reference types can. Applications that work with databases deal with the null value. Because of this, special nullable types were introduced into the C# language. Nullable types are instances of the System.Nullable<T> struct.
using System;

class CSharpApp
{
    static void Main()
    {
        Nullable<bool> male = null;
        int? age = null;

        Console.WriteLine(male.HasValue);
        Console.WriteLine(age.HasValue);
    }
}
A simple example demonstrating nullable types.
Nullable<bool> male = null;
int? age = null;
There are two ways how to declare a nullable type. Either with the Nullable<T> generic structure, in which the type is specified between the angle brackets. Or we can use a question mark after the type. The latter is in fact a shorthand for the first notation.
$ ./nullabletypes.exe 
False
False
Output.

DateTime(Value Type)

DateTime

The DateTime is value type. It represents an instant in time, typically expressed as a date and time of day.
using System;

class CSharpApp
{
    static void Main()
    {
        DateTime today;

        today = DateTime.Now;

        System.Console.WriteLine(today);
        System.Console.WriteLine(today.ToShortDateString());
        System.Console.WriteLine(today.ToShortTimeString());               

    }
}
We show today's date in three different formats. Date & time, date and time.
DateTime today;
We declare a variable of DateTime data type.
today = DateTime.Now;
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
System.Console.WriteLine(today);
This line prints the date in full format.
System.Console.WriteLine(today.ToShortDateString());
System.Console.WriteLine(today.ToShortTimeString());
The ToShortDateString() returns a short date string format, the ToShortTimeString() returns a short time string format.
$ ./date.exe 
10/15/2010 10:56:37 AM
10/15/2010
10:56 AM

Enumerations

Enumerations

Enumerated type (also called enumeration or enum) is a data type consisting of a set of named values. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. Enumerations make the code more readable.
using System;

class CSharpApp
{
    enum Days 
    {
        Monday,
        Tuesday,
        Wednesday,
        Thursday,
        Friday,
        Saturday,
        Sunday
    }

    static void Main()
    {

        Days day = Days.Monday;
        
        if (day == Days.Monday)
        {
            Console.WriteLine("It is Monday");
        }

        Console.WriteLine(day);

        foreach(int i in Enum.GetValues(typeof(Days)))
            Console.WriteLine(i);
    }
}
In our code example, we create an enumeration for week days.
enum Days 
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}
The enumeration is created with a enum keyword. The Monday, Tuesday ... barewords store in fact numbers 0..6.
Days day = Days.Monday;
We have a variable called day, which is of enumerated type Days. It is initialized to Monday.
if (day == Days.Monday)
{
    Console.WriteLine("It is Monday");
}
This code is more readable than if comparing a day variable to some number.
Console.WriteLine(day);
This line prints Monday to the console.
foreach(int i in Enum.GetValues(typeof(Days)))
    Console.WriteLine(i);
This loop prints 0..6 to the console. We get underlying types of the enum values. For a computer, an enum is just a number. The typeof is an operator used to obtain the System.Type object for a type. It is needed by the GetValues() method. This method returns an array of the values of in a specified enumeration. And the foreach keyword goes through the array, element by element and prints them to the terminal.

We further work with enumerations.
using System;

class CSharpApp
{
    public enum Seasons : byte
    {
        Spring = 1,
        Summer = 2,
        Autumn = 3,
        Winter = 4
    }

    static void Main()
    {
        Seasons s1 = Seasons.Spring;
        Seasons s2 = Seasons.Autumn;
        
        Console.WriteLine(s1);
        Console.WriteLine(s2);
    }
}
Seasons can be easily used as enums. We can specify the underlying type for the enum plus we can give exact values for them.
public enum Seasons : byte
{
    Spring = 1,
    Summer = 2,
    Autumn = 3,
    Winter = 4
}
With a colon and a data type we specify the underlying type for the enum. We also give each member a specific number.
Console.WriteLine(s1);
Console.WriteLine(s2);
These two lines print the enum values to the console.
$ ./seasons.exe 
Spring
Autumn
Output.

Friday, 21 December 2012

ASP.NET Life Cycle


The requesting of an ASP.NET page triggers a sequence of events that encompass the page life cycle. The Web browser sends a post request to the Web server. The Web server recognizes the ASP.NET file extension for the requested page and sends the request to the HTTP Page Handler class. The following list is a sampling of these events, numbered in the order in which they are triggered.
  1. PreInt: This is the entry point of the ASP.NET page life cycle - it is the pre-initialization, so you have access to the page before it is initialized. Controls can be created within this event. Also, master pages and themes can be accessed. You can check the IsPostBack property here to determine if it is the first time a page has been loaded.
  2. Init: This event fires when all controls on the page have been initialized and skin settings have been applied. You can use this event to work with control properties. The Init event of the page is not fired until all control Init events have triggered - this occurs from the bottom up.
  3. InitComplete: This event fires once all page and control initializations complete. This is the last event fired where ViewState is not set, so ViewState can be manipulated in this event.
  4. PreLoad: This event is triggered when all ViewState and Postback data have been loaded for the page and all of its controls - ViewState loads first, followed by Postback data.
  5. Load: This is the first event in the page life cycle where everything is loaded and has been set to its previous state (in the case of a postback). The page Load event occurs first followed by the Load event for all controls (recursively). This is where most coding is done, so you want to check the IsPostBack property to avoid unnecessary work.
  6. LoadComplete: This event is fired when the page is completely loaded. Place code here that requires everything on the page to be loaded.
  7. PreRender: This is the final stop in the page load cycle where you can make changes to page contents or controls. It is fired after all PostBack events and before ViewState has been saved. Also, this is where control databinding occurs.
  8. PreRenderComplete: This event is fired when PreRender is complete. Each control raises this event after databinding (when a control has its DataSourceID set).
  9. SaveStateComplete: This is triggered when view and control state have been saved for the page and all controls within it. At this point, you can make changes in the rendering of the page, but those changes will not be reflected on the next page postback since view state is already saved.
  10. Unload: This event fires for each control and then the page itself. It is fired when the HTML for the page is fully rendered. This is where you can take care of cleanup tasks, such as properly closing and disposing database connections.
An interesting caveat of the events fired with the loading of a page is the controls within the page and their events; that is, each control has its own event life cycle. The following code provides an example of the ordering of page and a couple control events. The ASP.NET source is listed first and followed by the codebehind source. It is a basic ASP.NET 4.0 Web Form with TextBox and Literal controls. The code does not include all events, but it does provide a subset to give you a feel for how they appear. You should notice the events specified in the individual controls that ties them to code blocks.
<%@ Page Title="Home Page" Language="C#"
MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebPageLifeCycle._Default"
OnPreInit="PreInitEvent" ViewStateMode="Enabled" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent" />
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent" OnPreInit="Content_Render">
<h2>
<asp:Literal runat="server" ID="litExample" OnInit="Literal_Init"></asp:Literal>
<asp:TextBox runat="server" ID="txtExample" OnInit="Textbox_Init"></asp:TextBox>
Working with the ASP.NET Page life cycle.
</h2>
</asp:Content>
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebPageLifeCycle {
public partial class _Default : System.Web.UI.Page    {
protected void Page_Load(object sender, EventArgs e)     {
Response.Write("Page_Load<br>");
}
protected void Page_LoadComplete(object sender, EventArgs e)  {
Response.Write("Page_LoadComplete<br>");
}
protected void Page_PreRender(object sender, EventArgs e)     {
Response.Write("Page_PreRender<br>");
}
protected void Page_Render(object sender, EventArgs e)     {
Response.Write("Page_Render<br>");
}
protected void PreInitEvent(object sender, EventArgs e)    {
Response.Write("OnPreInit<br>");
}
protected void Page_Init(object sender, EventArgs e)    {
Response.Write("Page_Init<br>");
}
protected void Literal_Init(object sender, EventArgs e)   {
Response.Write("Literal_Init<br>");
}
protected void Textbox_Init(object sender, EventArgs e)  {
Response.Write("Textbox_Init<br>");
}
protected void Page_InitComplete(object sender, EventArgs e)    {
Response.Write("Page_InitComplete<br>");
}
protected void Page_PreLoad(object sender, EventArgs e)    {
Response.Write("Page_PreLoad<br>");
}
protected void TextBox_Unload(object sender, EventArgs e)    {
// Cleanup
}  }  }
Notice the Unload event does not display anything since the Response object is not available in it, since the page and controls have been fully loaded when this event is triggered. The following lines are displayed on the page when it is loaded:
OnPreInit
Literal_Init
Textbox_Init
Page_Init
Page_InitComplete
Page_PreLoad
Page_Load
Page_LoadComplete
Page_PreRender

Monday, 17 September 2012

CSS Background


CSS background properties are used to define the background effects of an element.
CSS properties used for background effects:
  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
1.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
background-color:#b0c4de;
}
</style>
</head>

<body>

<h1>My CSS web page!</h1>
<p>Hello world! This is a W3Schools.com example.</p>

</body>
</html>


2.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h1
{
background-color:#6495ed;
}
p
{
background-color:#e0ffff;
}
div
{
background-color:#b0c4de;
}
</style>
</head>

<body>

<h1>CSS background-color example!</h1>
<div>
This is a text inside a div element.
<p>This paragraph has its own background color.</p>
We are still in the div element.
</div>

</body>
</html>


3.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {background-image:url('paper.gif');}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>

</html>

4.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {background-image:url('bgdesert.jpg');}
</style>
</head>

<body>
<h1>Hello World!</h1>
<p>This text is not easy to read on this background image.</p>
</body>

</html>


5.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
background-image:url('gradient2.png');
}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>

</html>


6.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
background-image:url('gradient2.png');
background-repeat:repeat-x;
}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>

</html>


7.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
background-image:url('img_tree.png');
background-repeat:no-repeat;
}
</style>
</head>

<body>
<h1>Hello World!</h1>
<p>W3Schools background image example.</p>
<p>The background image is only showing once, but it is disturbing the reader!</p>
</body>

</html>



8.
<!DOCTYPE html>
<html>
<head>

<style type="text/css">
body
{
background-image:url('img_tree.png');
background-repeat:no-repeat;
background-position:right top;
margin-right:200px;
}
</style>

</head>

<body>
<h1>Hello World!</h1>
<p>W3Schools background no-repeat, set position example.</p>
<p>Now the background image is only shown once, and positioned away from the text.</p>
<p>In this example we have also added a margin on the right side, so the background image will never disturb the text.</p>
</body>

</html>


9.

Background - Shorthand property

As you can see from the examples above, there are many properties to consider when dealing with backgrounds.
To shorten the code, it is also possible to specify all the properties in one single property. This is called a shorthand property.
The shorthand property for background is simply "background":



<!DOCTYPE html>
<html>
<head>

<style type="text/css">
body
{
background:#ffffff url('img_tree.png') no-repeat right top;
margin-right:200px;
}
</style>

</head>

<body>
<h1>Hello World!</h1>
<p>Now the background image is only shown once, and it is also positioned away from the text.</p>
<p>In this example we have also added a margin on the right side, so that the background image will not disturb the text.</p>
</body>

</html>

CSS position Property




Positioning

The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element's content is too big.
Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method.
There are four different positioning methods.

Static Positioning

HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page.
Static positioned elements are not affected by the top, bottom, left, and right properties.




1.

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h2
{
position:absolute;
left:100px;
top:150px;
}
</style>
</head>

<body>
<h2>This is a heading with an absolute position</h2>
<p>With absolute positioning, an element can be placed anywhere on a page. The heading below is placed 100px from the left of the page and 150px from the top of the page.</p>
</body>

</html>




Fixed Positioning

An element with fixed position is positioned relative to the browser window.
It will not move even if the window is scrolled:



2.



<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p.pos_fixed
{
position:fixed;
top:30px;
right:5px;
}
</style>
</head>
<body>

<p class="pos_fixed">Some more text</p>
<p><b>Note:</b> IE7 and IE8 supports the fixed value only if a
!DOCTYPE is specified.</p>
<p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p>
</body>
</html>



3.


<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h2.pos_left
{
position:relative;
left:-20px;
}

h2.pos_right
{
position:relative;
left:20px;
}
</style>
</head>

<body>
<h2>This is a heading with no position</h2>
<h2 class="pos_left">This heading is moved left according to its normal position</h2>
<h2 class="pos_right">This heading is moved right according to its normal position</h2>
<p>Relative positioning moves an element RELATIVE to its original position.</p>
<p>The style "left:-20px" subtracts 20 pixels from the element's original left position.</p>
<p>The style "left:20px" adds 20 pixels to the element's original left position.</p>
</body>

</html>


4.



<!DOCTYPE html>
<html>
<head>
<style type="text/css">
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
</head>

<body>
<h1>This is a heading</h1>
<img src="w3css.gif" width="100" height="140" />
<p>Because the image has a z-index of -1, it will be placed behind the text.</p>
</body>
</html>







CSS display Property




1.


<html>
<head>
<style type="text/css">
p {display:inline}
</style>
</head>
<body>

<p>These two paragraphs generates inline boxes, and it results in</p>

<p>no distance between the two elements.</p>

</body>
</html>


2.


<html>
<head>
<style type="text/css">
p {display:none}
</style>
</head>
<body>

<p>These two paragraphs generates inline boxes, and it results in</p>

<p>no distance between the two elements.</p>

</body>
</html>



3.

<html>
<head>
<style type="text/css">
p {display:block}
</style>
</head>
<body>

<p>These two paragraphs generates inline boxes, and it results in</p>

<p>no distance between the two elements.</p>

</body>
</html>

4.


<html>
<head>
<style type="text/css">
p {display:list-item}
</style>
</head>
<body>

<p>These two paragraphs generates inline boxes, and it results in</p>

<p>no distance between the two elements.</p>

</body>
</html>








Sunday, 16 September 2012

Page Lifecycle Events


Within each stage of the life cycle of a page, the page raises events that you can handle to run your own code which are listed below:

1) PreInit: It is raised before the initialization stage begins. If you want to change master page or themes dynamically, then you have to use this event.

2) Init: It is raised after all controls have been initialized. If you want to read or initialize control properties, then you have to use this event.

3) InitComplete: It is raised at the end of the page's initialization stage. If you want to make changes to view state that you want to make sure are persisted after the next postback.

4) PreLoad: It is raised after the page loads view state for itself and all controls. It processes postback data that is included with the Request instance.

5) Load: It is raised after the preload event. If you want to set properties in controls and to establish database connections, then you have to use this event.

6) LoadComplete: It is raised at the end of the event-handling stage. If you want to do tasks that require all other controls on the page be loaded, then you have to use this event.

7) PreRender: It is raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. If you want to make final changes to the contents of the page or its controls before the rendering stage begins, then you have to use this event.

8) PreRenderComplete: It is raised after each data bound control calls its DataBind() method.

9) SaveStateComplete: It is raised after view state and control state have been saved for the page and for all controls. If you make any changes to the page or controls at this point, it affect rendering, but the changes will not be retrieved on the next postback.

10) Unload: It is raised for each control and then for the page. If you want to do final cleanup for specific controls, such as closing control-specific database connections.

Thursday, 13 September 2012

OOPS Concepts


Class:
It is a collection of objects.
Object:
It is a real time entity.
An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can grip something or a Student (object) can give the name or address. In pure OOP terms an object is an instance of a class
The above template describe about object Student
Class is composed of three things name, attributes, and operations
public class student
{
}
student objstudent=new student ();

According to the above sample we can say that Student object, named objstudent, has created out of the student class.
In real world you will often find many individual objects all of the same kind. As an example, there may be thousands of other bicycles in existence, all of the same make and model. Each bicycle has built from the same blueprint. In object-oriented terms, we say that the bicycle is an instance of the class of objects known as bicycles. In the software world, though you may not have realized it, you have already used classes. For example, the Textbox control, you always used, is made out of the Textbox class, which defines its appearance and capabilities. Each time you drag a Textbox control, you are actually creating a new instance of the Textbox class.

Encapsulation:
Encapsulation is a process of binding the data members and member functions into a single unit.
Example for encapsulation is class. A class can contain data structures and methods.
Consider the following class
public class Aperture
{
public Aperture ()
{
}
protected double height;
protected double width;
protected double thickness;
public double get volume()
{
Double volume=height * width * thickness;
if (volume<0)
return 0;
return volume;
}
}
In this example we encapsulate some data such as height, width, thickness and method Get Volume. Other methods or objects can interact with this object through methods that have public access modifier

Abstraction:
Abstraction is a process of hiding the implementation details and displaying the essential features.
Example1: A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen, wireless antenna, web camera, usb ports, battery, speakers etc. To use it, you don't need to know how internally LCD screens, keyboard, web camera, battery, wireless antenna, speaker’s works. You just need to know how to operate the laptop by switching it on. Think about if you would have to call to the engineer who knows all internal details of the laptop before operating it. This would have highly expensive as well as not easy to use everywhere by everyone.
So here the Laptop is an object that is designed to hide its complexity.
How to abstract: - By using Access Specifiers
.Net has five access Specifiers
Public -- Accessible outside the class through object reference.
Private -- Accessible inside the class only through member functions.
Protected -- Just like private but Accessible in derived classes also through member functions.
Internal -- Visible inside the assembly. Accessible through objects.
Protected Internal -- Visible inside the assembly through objects and in derived classes outside the assembly through member functions.
Let’s try to understand by a practical example:-
public class Class1
{
int i; //No Access specifier means private
public int j; // Public
protected int k; //Protected data
internal int m; // Internal means visible inside assembly
protected internal int n; //inside assembly as well as to derived classes outside assembly
static int x; // This is also private
public static int y; //Static means shared across objects
[DllImport("MyDll.dll")]
public static extern int MyFoo(); //extern means declared in this assembly defined in some other assembly
public void myFoo2()
{
//Within a class if you create an object of same class then you can access all data members through object reference even private data too
Class1 obj = new Class1();
obj.i =10; //Error can’t access private data through object.But here it is accessible.:)
obj.j =10;
obj.k=10;
obj.m=10;
obj.n=10;
// obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10;
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
}

Now lets try to copy the same code inside Main method and try to compile
[STAThread]
static void Main()
{
//Access specifiers comes into picture only when you create object of class outside the class
Class1 obj = new Class1();
// obj.i =10; //Error can’t access private data through object.
obj.j =10;
// obj.k=10; //Error can’t access protected data through object.
obj.m=10;
obj.n=10;
// obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10; //Error can’t access private data outside class
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
What if Main is inside another assembly
[STAThread]
static void Main()
{
//Access specifiers comes into picture only when you create object of class outside the class
Class1 obj = new Class1();
// obj.i =10; //Error can’t access private data through object.
obj.j =10;
// obj.k=10; //Error can’t access protected data through object.
// obj.m=10; // Error can’t access internal data outside assembly
// obj.n=10; // Error can’t access internal data outside assembly

// obj.s =10; //Errror Static data can be accessed by class names only
Class1.x = 10; //Error can’t access private data outside class
// obj.y = 10; //Errror Static data can be accessed by class names only
Class1.y = 10;
}
In object-oriented software, complexity is managed by using abstraction.
Abstraction is a process that involves identifying the critical behavior of an object and eliminating irrelevant and complex details.
Inheritance:
Inheritance is a process of deriving the new class from already existing class
C# is a complete object oriented programming language. Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse existing code. Through effective use of inheritance, you can save lot of time in your programming and also reduce errors, which in turn will increase the quality of work and productivity. A simple example to understand inheritance in C#.

Using System;
Public class BaseClass
{
Public BaseClass ()
{
Console.WriteLine ("Base Class Constructor executed");
}

Public void Write ()
{
Console.WriteLine ("Write method in Base Class executed");
}
}

Public class ChildClass: BaseClass
{

Public ChildClass ()
{
Console.WriteLine("Child Class Constructor executed");
}

Public static void Main ()
{
ChildClass CC = new ChildClass ();
CC.Write ();
}
}
In the Main () method in ChildClass we create an instance of childclass. Then we call the write () method. If you observe the ChildClass does not have a write() method in it. This write () method has been inherited from the parent BaseClass.
The output of the above program is

Output:
Base Class Constructor executed
Child Class Constructor executed
Write method in Base Class executed

this output proves that when we create an instance of a child class, the base class constructor will automatically be called before the child class constructor. So in general Base classes are automatically instantiated before derived classes.
In C# the syntax for specifying BaseClass and ChildClass relationship is shown below. The base class is specified by adding a colon, ":", after the derived class identifier and then specifying the base class name.
Syntax: class ChildClassName: BaseClass
{
//Body
}
C# supports single class inheritance only. What this means is, your class can inherit from only one base class at a time. In the code snippet below, class C is trying to inherit from Class A and B at the same time. This is not allowed in C#. This will lead to a compile time error: Class 'C' cannot have multiple base classes: 'A' and 'B'.
public class A
{
}
public class B
{
}
public class C : A, B
{
}
In C# Multi-Level inheritance is possible. Code snippet below demonstrates mlti-level inheritance. Class B is derived from Class A. Class C is derived from Class B. So class C, will have access to all members present in both Class A and Class B. As a result of multi-level inheritance Class has access to A_Method(),B_Method() and C_Method().

Note: Classes can inherit from multiple interfaces at the same time. Interview Question: How can you implement multiple inheritance in C#? Ans : Using Interfaces. We will talk about interfaces in our later article.
Using System;
Public class A
{
Public void A_Method ()
{
Console.WriteLine ("Class A Method Called");
}
}
Public class B: A
{
Public void B_Method ()
{
Console.WriteLine ("Class A Method Called");
}
}
Public class C: B
{
Public void C_Method ()
{
Console.WriteLine ("Class A Method Called");
}

Public static void Main ()
{
C C1 = new C ();
C1.A_Method ();
C1.B_Method ();
C1.C_Method ();
}
}
When you derive a class from a base class, the derived class will inherit all members of the base class except constructors. In the code snippet below class B will inherit both M1 and M2 from Class A, but you cannot access M2 because of the private access modifier. Class members declared with a private access modifier can be accessed only with in the class. We will talk about access modifiers in our later article.

Common Interview Question: Are private class members inherited to the derived class?
Ans: Yes, the private members are also inherited in the derived class but we will not be able to access them. Trying to access a private base class member in the derived class will report a compile time error.
Using System;
Public class A
{
Public void M1 ()
{
}
Private void M2 ()
{
}
}

Public class B: A
{
Public static void Main ()
{
B B1 = new B ();
B1.M1 ();
//Error, Cannot access private member M2
//B1.M2 ();
}
}
Method Hiding and Inheritance We will look at an example of how to hide a method in C#. The Parent class has a write () method which is available to the child class. In the child class I have created a new write () method. So, now if I create an instance of child class and call the write () method, the child class write () method will be called. The child class is hiding the base class write () method. This is called method hiding.

If we want to call the parent class write () method, we would have to type cast the child object to Parent type and then call the write () method as shown in the code snippet below.
Using System;
Public class Parent
{
Public void Write ()
{
Console.WriteLine ("Parent Class write method");
}
}

Public class Child: Parent
{
Public new void Write ()
{
Console.WriteLine ("Child Class write method");
}

Public static void Main ()
{
Child C1 = new Child ();
C1.Write ();
//Type caste C1 to be of type Parent and call Write () method
((Parent) C1).Write ();
}
}
Polymorphism:
When a message can be processed in different ways is called polymorphism. Polymorphism means many forms.

Polymorphism is one of the fundamental concepts of OOP.

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 is of two types:
Compile time polymorphism/Overloading
Runtime polymorphism/Overriding
Compile Time Polymorphism

Compile time polymorphism is method and operators 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.

When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same prototype.

Caution: Don't confused method overloading with method overriding, they are different, unrelated concepts. But they sound similar.

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(float radius);

Practical example of Method Overloading (Compile Time Polymorphism)

using System;

namespace method_overloading
{
class Program
{
public class Print
{

public void display(string name)
{
Console.WriteLine ("Your name is : " + name);
}

public void display(int age, float marks)
{
Console.WriteLine ("Your age is : " + age);
Console.WriteLine ("Your marks are :" + marks);
}
}

static void Main(string[] args)
{

Print obj = new Print ();
obj.display ("George");
obj.display (34, 76.50f);
Console.ReadLine ();
}
}
}

Note: In the code if you observe display method is called two times. Display method will work according to the number of parameters and type of parameters.

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.

Method overloading showing many forms.

using System;

namespace method_overloading_polymorphism
{
Class Program
{
Public class Shape
{
Public void Area (float r)
{
float a = (float)3.14 * r;
// here we have used function overload with 1 parameter.
Console.WriteLine ("Area of a circle: {0}",a);
}

Public void Area(float l, float b)
{
float x = (float)l* b;
// here we have used function overload with 2 parameters.
Console.WriteLine ("Area of a rectangle: {0}",x);

}

public void Area(float a, float b, float c)
{
float s = (float)(a*b*c)/2;
// here we have used function overload with 3 parameters.
Console.WriteLine ("Area of a circle: {0}", s);
}
}

Static void Main (string[] args)
{
Shape ob = new Shape ();
ob.Area(2.0f);
ob.Area(20.0f,30.0f);
ob.Area(2.0f,3.0f,4.0f);
Console.ReadLine ();
}
}
}

Things to keep in mind while method overloading

If you use overload for method, there are couple of restrictions that the compiler imposes.

The rule is that overloads must be different in their signature, which means the name and the number and type of parameters.

There is no limit to how many overload of a method you can have. You simply declare them in a class, just as if they were different methods that happened to have the same name.

Constructors and Destructors:
Classes have complicated internal structures, including data and functions, object initialization and cleanup for classes is much more complicated than it is for simple data structures. Constructors and destructors are special member functions of classes that are used to construct and destroy class objects. Construction may involve memory allocation and initialization for objects. Destruction may involve cleanup and deallocation of memory for objects.
Constructors and destructors do not have return types nor can they return values.
References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.
Constructors cannot be declared with the keyword virtual.
Constructors and destructors cannot be declared static, const, or volatile.
Unions cannot contain class objects that have constructors or destructors.
Constructors and destructors obey the same access rules as member functions. For example, if you declare a constructor with protected access, only derived classes and friends can use it to create class objects.
The compiler automatically calls constructors when defining class objects and calls destructors when class objects go out of scope. A constructor does not allocate memory for the class object it’s this pointer refers to, but may allocate storage for more objects than its class object refers to. If memory allocation is required for objects, constructors can explicitly call the new operator. During cleanup, a destructor may release objects allocated by the corresponding constructor. To release objects, use the delete operator.
Example of Constructor
class C
{
private int x;
private int y;
public C (int i, int j)
{
x = i;
y = j;
}
public void display ()
{
Console.WriteLine(x + "i+" + y);
}
}
Example of Destructor
class D
{
public D ()
{
// constructor
}
~D ()
{
// Destructor
}
}

Sunday, 2 September 2012

Csharp Interview Questions



1) What is .Net Framework? What are the parts of .Net Framework?

2) What is JIT? Why it is called just-in-time?

3) What are the differences between string and StringBuilder?

4) What are the differences between collections and generics?

5) What is boxing and unboxing?

6) Define value types and reference types.

7) Define operator overloading, function overloading.

8) What is inheritance?

9) What is abstract class? What are differences between abstract class and interface?

10) What are classes and objects?

11) Is multiple inheritance is possble in c#?

12) What are differences between structures and classes?

13) What are the enums?

14) What are the delegates? Explain its types?

15) What are the assemblies? What are the differences between private and shared assemblies?

16) What is Ado.Net? What are the components of Ado.net?

17) What are the differences between connected and disconnected architecture in Ado.Net?

18) What are the differences between DataSet and DataReader?

19) What is connection string?

20) What is connection pooling?

21) What is the difference between OLEDB Provider and SqlClient?

22) Name the method that needs to be invoked on the DataAdapter control to fill the generated DataSet with data?

23) What is the use of the Connection object?

24) What is the use of the CommandBuilder class?

25) What is Maximum Pool Size in ADO.NET Connection String?

26) Explain in brief DataAdapter class in ADO.NET.

27) Difference between ExecuteScalar() and ExecuteNonQuery()?

28) What is basic use of Data View?

29) How can we perform transactions in .NET?

30) What’s difference between Optimistic and Pessimistic locking?

Friday, 24 August 2012

Validate email addresses using regular expressions

The local-part (the part before the "@" character) of the e-mail may use any of these ASCII characters [1]:
  • Uppercase and lowercase letters
  • The digits 0 through 9
  • The characters , ! # $ % & ' * + - / = ? ^ _ ` { | } ~
  • The character "." provided that it is not the first or last character in the local-part
The domain part of the address is much easier to handle. The dot separated domain labels can only include letters, digits and hyphens [1].
There are two regexps in this script. The first one will pass "normal looking" addresses like foo.bar@baz.example.com or foo+bar@example.com. This regexp won't, however, pass all syntactically valid addresses like foo,!#@example.com
// define a regular expression for "normal" addresses
$normal = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$";

To understand this expression you need to be familiar with regexp syntax. You'll find links to some good tutorials in the end of this article.
The first part, ^[a-z0-9_\+-]+ means that the address has to start with letters a-z, numbers 0-9 or characters "_", "+" or "-" The final "+" means there must be 1..n of these characters. A normal username, say jsmith2 would match this expression. It also matches to foo+bar
The regexp continues with (\.[a-z0-9_\+-]+)*. It means that the first characters defined before can be followed with a period "." and after that with the same set of characters than before the period. Because characters "." and "+" have special meaning in regexps they must be escaped with a backslash. The final * means there must be 0..n of these sequences. This way the regexp will match to strings firstname.lastname, firstname.long-middlename.lastname and foo.bar+baz
After these characters there must be a single "@" character. It must be followed by a domain label that consist of letters, numbers and hyphens. There can be 1..n domain labels separated with a period. The first label (without the period) is defined by [a-z0-9-]+. After this there can be 0..n similar sequences starting with a period. This is defined as (\.[a-z0-9-]+)*. At the time this article was written most email address end with a period followed by 2..4 letters (for example .fi or .info). The expression \.([a-z]{2,4})$ matches this.
The second regexp is supposed to match all syntactically valid addresses, even those that we don't see that often. The idea in this example is that the validator should pass those strange looking addresses but tell the user that it would probably be a good idea to double check the address.
// define a regular expression for "strange looking" but syntactically valid addresses
$validButRare = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";

This ugly regexp is actually quite similar to the one declared earlier. The period separated character sequences in the local-part can now include all the special characters defined in the RFC. Characters "$", "*", "+" "^", "{" and "|" all have their special meanings in regular expressions so they must be escaped with a backslash. The expression now allows the domain part to end with a period followed by 2..n letters such as .museum
You can use these regexps as follows (in PHP):
if (eregi($normal, $email)) {
  echo("The address $email is valid and looks normal.");
}

else if (eregi($validButRare, $email)) {
  echo("The address $email looks a bit strange but it is syntactically valid. You might want to check it for typos.");
}

else {
  echo("The address $email is not valid.");
}
These regexps were inspired by and modified from the article "Using Regular Expressions in PHP" by James Ussher-Smith [2]. The article uses email address validation as an example but the suggested regexp doesn't work with for example foo+bar@example.com.
You can use these regexps in your applications but please give credit to the original authors. Feel free to drop me an email if you liked this howto. :)

Limitations

  • The example here does not check that the length of local-part is <65
  • The example here does not check that the length of the domain name is is <256
  • The example here does not allow quoted strings in the local part (eg."Foo Bar"@example.com). Quoted strings are allowed in local-part but RFC 2821 warns that they should be avoided.

Saturday, 11 August 2012

Display Property in CSS?

Property Values

Value Description Play it
none The element will not be displayed at all Play it »
block The element is displayed as a block element (like paragraphs and headers). A block element has some whitespace above and below it and does not tolerate any HTML elements next to it Play it »
inline This is default. The element is displayed as an inline element (like span). An inline element has no line break before or after it, and it tolerates HTML elements next to it Play it »
inline-block The element is placed as an inline element (on the same line as adjacent content), but it behaves as a block element
inline-table The element is displayed as an inline table  
list-item The element is displayed as a list-item, which means that it has a bullet in front of it Play it »
table The element is displayed as a table
table-caption The element is displayed as a table caption
table-cell The element is displayed as a table cell
table-column The element is displayed as a table column
table-column-group The element is displayed as a table column group (like <colgroup>)
table-footer-group The element is displayed as a table footer row group
table-header-group The element is displayed as a table header row group
table-row The element is displayed as a table row
table-row-group The element is displayed as a table row group
inherit The value of the display property will be inherited from the parent element

Margin and Padding??

Margin

The margin clears an area around an element (outside the border). The margin does not have a background color, and is completely transparent.
The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used, to change all margins at once.

Possible Values

Value Description
auto The browser calculates a margin
length Specifies a margin in px, pt, cm, etc. Default value is 0px
% Specifies a margin in percent of the width of the containing element
inherit Specifies that the margin should be inherited from the parent element
Remark It is possible to use negative values, to overlap content.
 

Padding

The CSS padding properties define the space between the element border and the element content.


The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.
The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once.

Possible Values

Value Description
length Defines a fixed padding (in pixels, pt, em, etc.)
% Defines a padding in % of the containing element

CSS Box Model

The CSS Box Model

All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.
The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content.
The box model allows us to place a border around elements and space elements in relation to other elements.
The image below illustrates the box model:

CSS box-model Explanation of the different parts:
  • Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent
  • Border - A border that goes around the padding and content. The border is affected by the background color of the box
  • Padding - Clears an area around the content. The padding is affected by the background color of the box
  • Content - The content of the box, where text and images appear
In order to set the width and height of an element correctly in all browsers, you need to know how the box model works.

Width and Height of an Element

Remark Important: When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add the padding, borders and margins.
The total width of the element in the example below is 300px:
width:250px;
padding:10px;
border:5px solid gray;
margin:10px;
Let's do the math:
250px (width)
+ 20px (left and right padding)
+ 10px (left and right border)
+ 20px (left and right margin)
= 300px
Assume that you had only 250px of space. Let's make an element with a total width of 250px:

Example

width:220px;
padding:10px;
border:5px solid gray;
margin:0px;


The total width of an element should be calculated like this:
Total element width = width + left padding + right padding + left border + right border + left margin + right margin
The total height of an element should be calculated like this:
Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin

Browsers Compatibility Issue

The example above does not display properly in IE8 and earlier versions.
IE8 and earlier versions includes padding and border in the width, if a DOCTYPE is NOT declared.
To fix this problem, just add a DOCTYPE to the HTML page:

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
div.ex
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
</head>
</html>
 

 

Tuesday, 24 July 2012

Lists commonly are found in documents, including web pages.  They are an easy and effective way to itemize such things as elements, components, or ingredients.
Words or phrases which need to be set apart from the rest of the body of text can be emphasized with a “bullet” (a heavy dot used for calling attention to a particular section of text).  An empty tag called a “list” tag is used to do this:
  • <LI>: creates a bullet in front of text which is to be set apart for emphasis and causes all text after it to be indented, either until another list tag is detected or until the end of the list is reached.  It is used to itemize elements of “unordered” and “ordered” lists. Note:  A <BR> tag is not inserted at the end of an item beginning with a <LI> tag, as a line break automatically occurs at that point.
Since a list tag is an empty tag (that is, there is no negating counterpart </LI>), and since it indents the text following it, it cannot be alone; otherwise, the entire remainder of the document would be indented. Therefore, list tags (<LI>) must be incorporated between two non-empty tags.  One such pair of tags is called “unordered list” tags:
  • <UL>unordered list</UL>: delineates a list, where the items are generally of equal importance and do not need to go in any particular order.  Each item begins with a <LI> tag.  Unordered lists may be nested inside unordered lists or inside any other types of lists (one list inside of another list inside of another list).  A line space automatically is inserted before and after an unordered list (that is, an entire line is skipped between an unordered list and any text before and after it), except for (on most browsers) a list nested within another list.
The initial <UL> tag may contain within it this parameter as part of the command:
  • TYPE="DISC"|"SQUARE"|"CIRCLE": designates the appearance of the bullets preceding the listed items.  Many browsers support only the "DISC" attribute.    "DISC" causes each bullet to appear as a solid, round disc.
       "SQUARE" causes each bullet to appear as a solid square.   (Many browsers do not recognize the "SQUARE" attribute.)
       "CIRCLE" causes each bullet to appear as an empty circle.   (Many browsers do not recognize the "CIRCLE" attribute.)
    Note:  On some browsers, "DISC" is the default bullet.  On other browsers, "CIRCLE" is the default bullet.
Here, items in an unordered list are accentuated: <FONT SIZE="4"><P>During a routine eye examination, a pathology within the body sometimes can be detected in the eye, especially if the disease process is in a moderate to advanced stage.  Here are 2 such cases, along with their intraocular signs:
<UL TYPE="CIRCLE">
<LI><I>diabetic</I> retinal signs:
<UL TYPE="SQUARE">
<LI>CSME (clinically significant macular edema)
<LI>cotton wool spots (infarcted areas)
<LI>neovascular formation
<LI>blot and dot hemorrhages
</UL>
<LI><I>hypertensive (high blood pressure)</I> retinal signs:
<UL TYPE="SQUARE">
<LI>blood vessel crossing defects (arteries compressing veins)
<LI>exudative changes in and around the macula ("star-burst" pattern)
<LI>hemorrhages
<LI>narrowing of retinal arterioles, including the "boxcar" effect
</UL>
</UL></P></FONT>
and would be marked up like this: During a routine eye examination, a pathology within the body sometimes can be detected in the eye, especially if the disease process is in a moderate to advanced stage.  Here are 2 such cases, along with their intraocular signs:

  • diabetic retinal signs:
    • CSME (clinically significant macular edema)
    • cotton wool spots (infarcted areas)
    • neovascular formation
    • blot and dot hemorrhages
  • hypertensive (high blood pressure) retinal signs:
    • blood vessel crossing defects (arteries compressing veins)
    • exudative changes in and around the macula ("star-burst" pattern)
    • hemorrhages
    • narrowing of retinal arterioles, including the "boxcar" effect
  • Note:  If circular bullets and/or square bullets do not appear in the example above, then your browser does not recognize the "CIRCLE" bullet attribute and/or the "SQUARE" bullet attribute.

List tags (<LI>) also may be incorporated within another pair of non-empty tags, called “ordered list” tags:
  • <OL>ordered list</OL>: delineates a list, where the items are in sequential, numerical order.  Each item begins with a <LI> tag.  Ordered lists may be nested inside ordered lists or inside any other types of lists (one list inside of another list inside of another list).  A line space automatically is inserted before and after an ordered list (that is, an entire line is skipped between an ordered list and any text before and after it), except for (on most browsers) a list nested within another list.
The initial <OL> tag may contain within it this parameter as part of the command:
  • TYPE="I"|"A"|"1"|"a"|"i": designates the appearance of the numbers preceding the items in the list and, therefore, is conducive to building an outline using nested ordered lists.    "I" causes the items to be numbered I, II, III, IV, V, VI, VII, etc.
       "A" causes the items to be numbered A, B, C, D, E, F, G, etc.
       "1" (the default) causes the items to be numbered 1, 2, 3, 4, 5, 6, 7, etc.
       "a" causes the items to be numbered a, b, c, d, e, f, g, etc.
       "i" cause the items to be numbered i, ii, iii, iv, v, vi, vii, etc.
In an ordered list, the list (<LI>) tag may contain within it this parameter:
  • VALUE="1"|"2"|"3"|...|"N": immediately changes the number of that item to the Nth term of that particular numbering type.  For example, VALUE="4" would label that item in the sequence as follows:    for TYPE="I" that item would be “IV”;
       for TYPE="A" that item would be “D”;
       for TYPE="1" that item would be “4”;
       for TYPE="a" that item would be “d”;
       for TYPE="i" that item would be “iv.”
This is how items in an ordered list may be enumerated: <FONT SIZE="4"><P>As listed in the <I>Jackson Heights Journal</I>, Jackson Heights Middle School ranked <B>5th</B> in the city-wide achievement test given last week:
<OL TYPE="I">
<LI>Oakfield Middle School
<OL TYPE="A">
<LI>Tod Hastings
<OL TYPE="1">
<LI>Math (#3)
<LI>History (#2)
<LI>Science (#2)
</OL>
<LI>Bonita Chavez
<OL TYPE="1">
<LI>Math (#1)
<LI>History (#4)
<LI>Science (#3)
</OL>
</OL>
<LI>Parkview Mid-High
<OL TYPE="A">
<LI>Jacque Russell
<OL TYPE="1">
<LI>Math (#2)
<LI>History (#5)
<LI>Science (#4)
</OL>
<LI>Dwayne Clancy
<OL TYPE="1">
<LI>Math (#4)
<LI>History (#7)
<LI>Science (#1)
</OL>
</OL>
.<BR>
.<BR>
.<BR>
<LI VALUE="5">Jackson Heights Middle School
<OL TYPE="A">
<LI>Christine Quon
<OL TYPE="1">
<LI>Math (#7)
<LI>History (#6)
<LI>Science (#5)
</OL>
<LI>Roger Dietz
<OL TYPE="1">
<LI>Math (#5)
<LI>History (#8)
<LI>Science (#7)
</OL>
</OL>
</OL></P></FONT>
and would appear like this: As listed in the Jackson Heights Journal, Jackson Heights Middle School ranked 5th in the city-wide achievement test given last week:

  1. Oakfield Middle School
    1. Tod Hastings
      1. Math (#3)
      2. History (#2)
      3. Science (#2)
    2. Bonita Chavez
      1. Math (#1)
      2. History (#4)
      3. Science (#3)
  2. Parkview Mid-High
    1. Jacque Russell
      1. Math (#2)
      2. History (#5)
      3. Science (#4)
    2. Dwayne Clancy
      1. Math (#4)
      2. History (#7)
      3. Science (#1)
    .
    .
    .
  3. Jackson Heights Middle School
    1. Christine Quon
      1. Math (#7)
      2. History (#6)
      3. Science (#5)
    2. Roger Dietz
      1. Math (#5)
      2. History (#8)
      3. Science (#7)

Sometimes, it is helpful to include a glossary of terms in a document, which is accomplished with non-emptydefinition list” tags:
  • <DL>definition list</DL>: delineates a list, where the items are individual terms paired with their definitions, and each definition is indented and placed one line down from each term.  Definition lists may be nested inside definition lists or inside any other types of lists (one list inside of another list inside of another list).  A line space automatically is inserted before and after a definition list (that is, an entire line is skipped between a definition list and any text before and after it), excluding a list nested within another list.
  • <DL COMPACT>definition list</DL>: same as <DL> & </DL>, except each definition is placed on the same line as each term.
Within the definition list are terms, each marked with an emptydefinition-list term” tag, as well as the actual definitions of the terms, each marked with an emptydefinition-list definition” tag:
  • <DT>: creates (but does not place bullets in front of) terms included in a glossary or definition list.
  • <DD>: indents (but does not place bullets in front of) definitions of terms in a glossary or definition list.
Here is a short list of common Internet terms: <DL><FONT SIZE="4">
<DT>HTML
<DD>Hypertext Markup Language
<DT>TP
<DD>Transfer Protocol
<DL>
<DT>FTP
<DD>File Transfer Protocol
<DT>HTTP
<DD>Hypertext Transfer Protocol
</DL>
<DT>URL
<DD>Uniform Resource Locator (= web address)
<DT>WWW
<DD>World Wide Web</FONT>
</DL>
and how this list would look on a browser:
HTML
Hypertext Markup Language
TP
Transfer Protocol
FTP
File Transfer Protocol
HTTP
Hypertext Transfer Protocol
URL
Uniform Resource Locator (= web address)
WWW
World Wide Web
When an enumerated list is required, with each item (“definition”) to be placed on the same line as each number (“term”), a compacted list could be used:
<DL COMPACT><FONT SIZE="4">
<DT>1<DD>HTML
<DT>1<DD>TP
<DT>1<DD>URL
<DT>1<DD>WWW</FONT>
</DL>
and would look this way:
1
HTML
2
TP
3
URL
4
WWW

At times it is beneficial to create a list of related, indented terms which are not preceded by either bullets or numbers.  In such cases, non-emptydirectory list” tags may be used:
  • <DIR>directory list</DIR>: creates a directory listing where each entry is indented (on most browsers).  Directory lists may be nested inside directory lists or inside any other types of lists (one list inside of another list inside of another list).  On most browsers, a line space automatically is inserted before and after a directory list (that is, an entire line is skipped between a directory list and any text before and after it), except for (on many browsers) a list nested within another list. Note:  An example of directory lists nested within an unordered list may be seen by viewing the list of hyperlinks in the HTML source code of the initial page (“Ted’s HTML Tutorial”) of this portion of my web site.
The easiest way to understand directory list tags is to see that <DIR> tags indent the text coming after them, while </DIR> tags outdent the text coming after them.  The difference between <DIR> & </DIR> tags and <BLOCKQUOTE> & </BLOCKQUOTE> tags is that directory list tags indent only the left margin of the text between them, whereas blockquote tags indent both the left and right margins of the text between them. One example of a directory list is the table of contents of an HTML document, where each item in the table of contents is a hyperlink jumping directly to the site listed:
<FONT SIZE="4"><H2>Table of Contents</H2><DIR>
<A HREF="P-I">Part I</A><DIR>
<A HREF="P-I_C-1">Chapter 1</A><DIR>
<A HREF="P-I_C-1_S-A">Section A</A><BR>
<A HREF="P-I_C-1_S-B">Section B</A></DIR>
<A HREF="P-I_C-2">Chapter 2</A><DIR>
<A HREF="P-I_C-2_S-A">Section A</A><BR>
<A HREF="P-I_C-2_S-B">Section B</A></DIR></DIR>
<A HREF="P-II">Part II</A><DIR>
<A HREF="P-II_C-3">Chapter 3</A><DIR>
<A HREF="P-II_C-3_S-A">Section A</A><BR>
<A HREF="P-II_C-3_S-B">Section B</A></DIR>
<A HREF="P-II_C-4">Chapter 4</A><DIR>
<A HREF="P-II_C-4_S-A">Section A</A><BR>
<A HREF="P-II_C-4_S-B">Section B</A></DIR></DIR></DIR></FONT>
and which would look like this when marked up:

Table of Contents

Part I Chapter 1 Section A
Section B
Chapter 2 Section A
Section B
Part II Chapter 3 Section A
Section B
Chapter 4 Section A Section B