Posts

Showing posts from January, 2009

Xml Rss Blog Feed In Asp.Net

Image
Rss feed using XmlDataSource Control & Data bound control( here I had used datalist)

Method Overloading Example

public class AddingNumbers { /// /// Method Overloading /// /// Example : Console.WriteLine() & System.Math.Sign() /// overloading a method when you for some reason need a couple of methods that take different perameters, /// but conceptually do the same thing. /// /// /// /// public int Add(int a, int b) { return a + b; } public int Add(int a, int b, int c) { return a + b + c; } // Error'OOPS_Overloading.Program.AddingNumbers' already defines a member called 'Add' with the same parameter types C:\Documents and Settings\milindm\My Documents\Visual Studio 2005\Projects\OOPS_Overloading\OOPS_Overloading\Program.cs 21 27 OOPS_Overloading /* public string Add(int a, int b, int c) { return Convert.ToString

Interface Example

Interface Example interface IPoint { // Property signatures: int x { get; set;} int y { get; set;} // method signature void print_points(); } class Point : IPoint { // Fields: private int _x; private int _y; // Constructor: public Point(int x, int y) { _x = x; _y = y; } // Property Implementation: public int x { get { return _x; } set { _x = value; } } public int y { get { return _y; } set { _y = value; } } // Method Implementation public void print_points() { Console.WriteLine("{0} {1}", _x, _y); } } class Program { /// /// Interface /// /// -

Abstract Example

abstract class BaseClass // Abstract class { protected int _x = 100; protected int _y = 150; public abstract void AbstractMethod(); // Abstract method public abstract int X { get; } public abstract int Y { get; } } class Program : BaseClass { /// /// Abstract Class /// /// Use the abstract modifier in a method or property declaration to indicate that the method /// or property does not contain implementation. /// Use the abstract modifier in a class declaration to indicate that a class is intended only /// to be a base class of other classes. /// The abstract modifier can be used with classes, methods, properties, indexers, and events. /// /// -An abstract class cannot be instantiated. /// -An abstract class class cannot be inherited. /// -An abstract class may contain abstract methods and accessors.

Static Constructor Example

/// /// A static constructor is used to initialize any static data, or to perform a particular action that /// needs performed once only. It is called automatically before the first instance is created or any /// static members are referenced. /// /// -A static constructor does not take access modifiers or have parameters. /// -A static constructor is called automatically to initialize the class before the first instance is created /// or any static members are referenced. /// -A static constructor cannot be called directly. /// -The user has no control on when the static constructor is executed in the program. /// -A typical use of static constructors is when the class is using a log file and the constructor is used /// to write entries to this file. /// -Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor /// can call the LoadLibrary

Sealed Class Example

/// /// Sealed Class /// /// You can Initiate the class /// You can not Inherit the class : class B : A { } /// Structs are implicitly sealed; therefore, they cannot be inherited. /// System.Threading.Thread /// /// sealed class A { public A() { } public void Test1() { } public static void Test2() { } } /*//Error : 'OOPS_Sealed.Program.B': cannot derive from sealed type 'OOPS_Sealed.Program.A' class B : A { }*/ static void Main(string[] args) { A obj = new A(); A.Test2(); }

Go through Static class example

/// /// Static Class /// /// You can not Initiate : A obj = new A(); /// You can not Inherited : class B : A { } /// All the members in Static class are static /// They cannot contain Instance Constructors : public A { } /// /// static class A { /* Error 'test': cannot declare instance members in a static class public void test() { } */ public static void test() { } } /*Error cannot derive from static class 'OOPS_Concept.Program.A' class B : A { } */ static void Main(string[] args) { /* Error 1 Cannot declare variable of static type 'OOPS_Concept.Program.A' Error 2 Cannot create an instance of the static class 'OOPS_Concept.Program.A'