THANKS FOR WATCHING MY BLOG.IF ANY PROBLEM PLEASE COMMENT

Wednesday, 19 March 2014

Inheritance

 The given C sharp example decalres abstract class Shape
* that implements polymorpism by overloading and
* overridding methods. The clas Shape2 consists
* of a virtual method ShapeType(). The method
* CalculateArea() is implemented twice by having
* different signatures and different return types.
* The class Square inherits the base class Shape2
* and overrides the base class method called ShapeType().
* The main() method creates an instance of the derieved
* class Square and the base class Shape2. the instance
* of the base class Shape2 invokes the method
* CalculateArea(). Depending on the parameter that
* the method CalcualteArea() takes, the apropiate
* method is called.
*/
using System;

namespace Inherit
{
class Shape2
{
public virtual void ShapeType()
{
Console.WriteLine("This message will be used to display type of the shape");
}
public int CalculateArea(int side)
{
return side * side;
}
public double CalculateArea(double baseBreadth, double height)
{
return 05 * baseBreadth * height;
}
}
class Square :Shape2
{
public override void ShapeType()
{
Console.WriteLine("A square is a Polygon");
}
public static void Main(string[] args)
{
Square sqr = new Square();
sqr.ShapeType();
Console.WriteLine("Area IS : "+sqr.CalculateArea(6));
}
}
}

//Output

//A square is a Polygon
//Area IS : 36

Multi level inheritance

/* Write a program in C sharp on parameteried
construtor in multilevel inheritance*
*/
using System;

namespace Inherit
{
class Metals
{
string _metalType;
public Metals(String type)
{
_metalType = type;
Console.WriteLine("Metal\t\t:" + _metalType);
}
}

class SteelCompany : Metals
{
string _grade;
public SteelCompany(string grade) : base("Steel")
{
_grade = grade;
Console.WriteLine("Grade\t\t:" + _grade);
}
}
class Automobiles : SteelCompany
{
string _part;
public Automobiles(string part): base("Cast Iron")
{
_part = part;
Console.WriteLine("Part\t\t:" + _part);
}
public static void Main()
{
Automobiles auto = new Automobiles("Mercedes");
}
}
}

//Output

//Metal :Steel
//Grade :Cast Iron
//Part :Mercedes

Multilevel Inhetitance 2

/* C# program to implemmet multi level inheritance.
This program demonstrates how base class constructors are inherited using multilevel inheritance. */

using System;

namespace Inherit
{
class Shape
{
public Shape()
{
Console.WriteLine("Constructor of base class Shape");
}
}
class Polygon : Shape
{
public Polygon()
{
Console.WriteLine("Constructor of Base class Polygon");
}
}
class Quad : Polygon
{
public Quad()
{
Console.WriteLine("Contructor of class Quad");
}
public static void Main(string[] args)
{
Quad obj= new Quad();
}
}
}

//Output

//Constructor of base class Shape
//Constructor of Base class Polygon
//Contructor of class Quad
/* Program in C# for implementation of multiway inheritance */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inherit
{
class One:Mammal
{
public void Noise()
{
Console.WriteLine("Dog Barks");
}

static void Main(string[] args)
{
One obj = new One();
obj.Eat();
obj.feature();
obj.Noise();
}
}

class Animal
{
public void Eat()
{
Console.WriteLine("Every Animal Eats Something");
}
}

class Mammal : Animal
{
public void feature()
{
Console.WriteLine("Mammal Gives birth to young ones");
}
}
}
//Output

//Every Animal Eats Something
//Mammal Gives birth to young ones
//Dog Barks

C# CONSOLE


ConsoleConsole programs are easy to develop. They read input. They write output.
In Visual Studio,
please select New Project
and then Console Application. Many useful methods are available.
Visual Studio
Programs are arguably the most complicated engineering artifacts ever produced; they consist of many many details, every one of which must be correct before the program will work completely. Aho et al., p. 23

Intro

This program is a quick introduction to the Console class. It simply prints a series of characters to the terminal window. This does not result in a world-class visual experience. It is useful for certain type of applications.
Based on:

.NET 4.5

Program that uses Console type: C#

using System;

class Program
{
    static void Main()
    {
 // Write to console window.
 Console.WriteLine("Thanks for visiting!");
    }
}
PrintWrite. You will want to display information when the console program executes. If the program takes a long time to finish, printing the status of the operation is useful as users won't assume the program froze.
WriteWriteLineSetOut
Colors:You can change the foreground color and background color of text you write to the console.
Console ColorsRead. The Console type has many methods available to read in user input from the terminal window. When the user types in characters, you can read that instantly with ReadKey or when the Enter key is pressed, using ReadLine.
ReadReadKeyReadLineFour-way arrowArguments. It is useful to pass string arguments to your console programs. You can do this by creating a shortcut in Windows to the actual executable. We write the C# code to process the arguments.
Main, ArgsArgs LoopEnvironment.GetCommandLineArgsHeight and width. You can control the height of your console window with the Console.WindowHeight property. The Console.LargestWindowHeight property can help you determine the optimum height.
WindowHeight
Also:Annoying beeps are occasionally useful in programs. We take a humorous look at the Beep method on the Console type.
Beep

Title

Console.Title usageIn this example program, we use a while true loop and simply set the Console.Title property to whatever the user typed into the console. When you run this program, you can change the title of the console window by entering text.
Tip:Console.Title allows us to change the console window title. We can use it to reduce the amount of text written to the screen.
Program that uses Title property: C#

using System;

class Program
{
    static void Main()
    {
 while (true)
 {
     // Assign Console.Title property to string returned by ReadLine.
     Console.Title = Console.ReadLine();
 }
    }
}

CapsLock

This program simply prints the value returned by Console.CapsLock every one second. When you execute it, try pressing the caps lock key. It will start printing True when the key is pressed.
Sleep
Program that uses CapsLock property: C#

using System;
using System.Threading;

class Program
{
    static void Main()
    {
 while (true)
 {
     Thread.Sleep(1000);
     bool capsLock = Console.CapsLock;
     Console.WriteLine(capsLock);
 }
    }
}

Output

False
False
True
True
True
False
True
True
Programming tipThe Console.CapsLock property could be used in several different ways. If a program is requiring a password to be entered, you could print an error message if caps lock is pressed and the password is incorrect.
And:You could even add a separate "mode" in your program depending on whether caps lock is pressed.
So:With Console.CapsLock we detect whether caps lock is enabled on the computer. This property cannot be assigned.

NumberLock

PropertyThis program introduces a simple loop where the current value of the Console.NumberLock property is printed to the console every one second. As this program executes, you can press Num Lock and the output of the program will change.
Program that uses NumberLock: C#

using System;
using System.Threading;

class Program
{
    static void Main()
    {
 while (true)
 {
     Console.WriteLine(Console.NumberLock);
     Thread.Sleep(1000);
 }
    }
}

Output

False
False
True
True
False
False
Pound symbolYou cannot set the value of the NumberLock property. If you do not want the key pressed, you must tell the user to press it again. On most keyboards, a light will glow if the Num Lock key is pressed.
Tip:Console.NumberLock provides a way to determine if a keyboard key is pressed.
And:In some programs the Num Lock key is used to change the keyboard mode and the program's response to key presses.

Programs

ProgramLet's explore some complete or nearly-complete program implementations. These programs are useful for testing purposes. Long or complex programs are not available here. No downloads are available in binary form.
Note:This site contains thousands of complete programs. Most are not useful tools for anything except demonstration.
Benchmark. One useful program implementation is a benchmarking harness. This program will test two pieces of C# code. It then prints results of the time required for each piece to execute.
BenchmarksC# languageWeb pages. These programs download specified web pages. They are useful for when you are testing a web site. The code in these programs was used extensively in the development of this website.
Decompress GZIPWebClient
Also:You can play sounds in your C# program using the SoundPlayer type. This program requires you to specify a WAV file to play.
SoundPlayer

Summary

Console programs are ideal for situations where the user interface is not important. They provide a way to output important information. And they do not over-complicate the software with graphical user interface code.