StatCounter

View My Stats

Friday, February 6, 2009

Class,Inner Class(or)Nested class Example in C#

Class,Inner Class(or)Nested class Example in C#


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

namespace ConsoleExample
{
public class OuterClass
{
public void OuterClassFunction()
{
Console.WriteLine("I am in Outer Class Function");
}
//Reinitialize the class

public InnerClass abc()
{
return new InnerClass();

}

public class InnerClass
{

public OuterClass OutC()
{
return new OuterClass();
}

public string PublicInner;
private string privateInner;

public InnerClass()
{

}

public void InnerClassFunction()
{
Console.WriteLine("I am in InnerClass");

}

void PrivateFunction_InnerClass()
{
Console.WriteLine("I am a Private function Of InnerClass");
}
}
}
}
________________________________________________________________________

For the Above example the Instance are named as abc(),OutC()


To Call an instance Methods from the main function:


static void Main(string[] args)
{
//Program Obj = new Program();
//Obj.ReadAssembly();
OuterClass.InnerClass Obj = new OuterClass.InnerClass();
Obj.OutC().OuterClassFunction();
Console.ReadLine();

}

__________________________________________________________________
Nested Class and Ordinary Class Explainations.



A nested class is declared in the same manner as a normal class declaration. The difference is that a nested class has access to all of the available modifiers.

The this keyword reference in the inner class only holds a reference to the inner class. Data members of the outer class are not accessible using the this reference in the inner class. If this is needed, pass a reference of the outer class into the constructor of the inner class.

static members of the outer class are available in the inner class irrespective of the accessibility level.

ISerializable implementation example

ISerializable implementation example


Introduction

Some times, we need to record data according to a given object into a file in order to either stock them or to send them via network, and such task are very needed especially in the asp or the distributed applications case. This kind of task is called serialization. There are several methods to do that, but never the less, I give one alternative among them as a part of this article. This method consists on implementing the ISerializable interface.

Let's consider a class who's called Person and here is its description:



Figure 1

The Person class code is as follow:

public class Person

{

private string _FirstName;

private string _LastName;

public string FirstName

{

get { return _FirstName; }

set { _FirstName = value; }

}

public string LastName

{

get { return _LastName; }

set { _LastName = value; }

}

public Person()

{

}

public Person(string FirstName, string LastName)

{

this.FirstName = FirstName;

this.LastName = LastName;

}
}

To serialize objects issued from this class, we should implement the ISerializable interface; this last one has a method ISerializable.GetObjectData that it should be implemented.

This is how to implement the ISerializable interface:

public class Person:ISerializable

{

private string _FirstName;

private string _LastName;

public string FirstName

{

get { return _FirstName; }

set { _FirstName = value; }

}

public string LastName

{

get { return _LastName; }

set { _LastName = value; }

}

public Person()

{

}

public Person(string FirstName, string LastName)

{

this.FirstName = FirstName;

this.LastName = LastName;

}

void ISerializable.GetObjectData(SerializationInfo oInfo, StreamingContext oContext)

{

oInfo.AddValue("FirstName", this.FirstName);

oInfo.AddValue("LastName", this.LastName);

}

}

The GetObjectData ( ) method hasn't to be marked as public otherwise an error indicates that the modifier public in not valid for this item will be generated.

Dynamic Fill Combobox values through javascript

Dynamic Fill Combobox values through javascript


Examople:

Call the fuction at the button click event

function DynamicComboAdd()
{
var Obj=document.getElementById('DropDownList1');
Obj.options.length=2;
Obj.options[0].text='hi';
Obj.options[0].value='hi';
Obj.options[1].text='hii';
Obj.options[1].value='hii';
return false;
}

Simple XML Text Reader Example in C# Console Appln

Simple XML Text Reader Example in C# Console Appln


using System;
using System.Xml;

namespace ReadXMLfromFile
{
///


/// Summary description for Class1.
///
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("books.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
}

How to hook the IIS

How to hook the IIS


To hook the iis in our system we need to monitor the w3wp.exe in that concern system.


if u hook this w3wp.exe file u can able to monitor what are all the operations are undergone in the

IIS while loading a particular page

Use of Private and Public

Use of Private and Public


In Normal .Net Keep sight on using private and public variab HFle (or) property or anything else

carefully.It will al so degrade the system performance.

By default all the public properties/variable/anythings are XML serialized.So whenever you want to use it globally declare it globally.(or) else declare it as as a private property.

Through this we can reduce the time to take for serialization.

Friday, April 18, 2008

Checking Numeric (Or) Not using Regular Expression

Checking Numeric (Or) Not using Regular Expression


const string ALL_NUMERIC_PATTERN = "[a-z|A-Z]";
static readonly Regex All_Numeric_Regex =new Regex(ALL_NUMERIC_PATTERN);

All_Numeric_Regex .IsMatch(string Value);