4th june

1,046 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,046
On SlideShare
0
From Embeds
0
Number of Embeds
175
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

4th june

  1. 1. NAMESPACES&CLASSES<br />4thJune 2010<br />
  2. 2. NESTED NAMESPACES<br />using System;namespaceOutNamespace{<br /> namespaceWorkNamespace { <br />/// can be placed some classes, structures etc. }<br />}<br />
  3. 3. CLASSES<br />class TestClass<br /> {<br />// Methods, properties, fields, events, delegates <br />// and nested classes go here. <br /> }<br />
  4. 4. CLASS INHERITANCE<br />
  5. 5. Classes<br />// Namespace Declarationusing System;// helper classclass OutputClass {    string myString;    // Constructor    public OutputClass(string inputString)     {        myString = inputString;    }    // Instance Method    public void printString()     {        Console.WriteLine("{0}", myString);    }    // Destructor    ~OutputClass()     {        // Some resource cleanup routines    }}<br />// Program start classclass ExampleClass {    // Main begins program execution.    public static void Main()     {        // Instance of OutputClass        OutputClassoutCl = new OutputClass("This is printed by the output class.");        // Call Output class' method        outCl.printString();     }}<br />
  6. 6. INHERITANCE EXAMPLE<br />using System;public class ParentClass{    public ParentClass()    {        Console.WriteLine("Parent Constructor.");    }    public void print()    {        Console.WriteLine("I'm a Parent Class.");    }}public class ChildClass : ParentClass{    public ChildClass()    {        Console.WriteLine("Child Constructor.");    }    public static void Main()    {        ChildClass child = new ChildClass();        child.print();    }}<br />
  7. 7. EXAMPLE 2<br />using System;<br /> <br />public class Parent<br />{<br />    string parentString;<br />    public Parent()<br />    {<br />        Console.WriteLine("Parent Constructor.");<br />    }<br />    public Parent(string myString)<br />    {<br />        parentString = myString;<br />        Console.WriteLine(parentString);<br />    }<br />    public void print()<br />    {<br />        Console.WriteLine("I'm a Parent Class.");<br />    }<br />}<br /> <br />public class Child : Parent<br />{<br />    public Child() : base("From Derived")<br />    {<br />        Console.WriteLine("Child Constructor.");<br />    }<br />    public new void print()<br />    {<br />        base.print();<br />        Console.WriteLine("I'm a Child Class.");<br />    }<br />    public static void Main()<br />    {<br />        Child child = new Child();<br />        child.print();<br />        ((Parent)child).print();<br />    }<br />}<br />
  8. 8. Types of Statements in C#<br />the if statement<br />switch statement<br />the for loop<br />the while loop<br />the do…while loop<br />the foreachloop<br />

×