Using Block inside the void Main in c#.NET,ASP.NET

July 20, 2008

We can’t able to use the using block inside the

public static void main(String args[])
{
using (ReadingFile Rf = new ReadingFile())
{
Rf.ReadFile();
}
}

Like the above usage.Because the System.IDisposible implisitely

called inside the static void main(String args[]) function.

Inner Class,Creating an Instance Of the Class

July 20, 2008

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.

Variable Passing in C#.Net

July 20, 2008

class PropertiesExplaination

{

void OrdinaryAccessMethod(params int[] Params)
{
Console.WriteLine(Params.Length);
}

static void Main(string[] args)
{
PropertiesExplaination Obj = new PropertiesExplaination();
Obj.a = 1;
Obj.OrdinaryAccessMethod(Obj.a,Obj.a+1,Obj.a+3);
Console.Read();
}

}

For the above Example PropertiesExplaination is a Class Name and  OrdinaryAccessMethod is a sample method.

params-> is a Keyword to Pass a Array of Variables.

For the above example I am passing an array of Integer values to the Method of OrdinaryAccessMethod(Method Name)

NameValueCollection in C#.NET

July 20, 2008

The name value collection is same like the HashTable.

We can set the Object value and the Key to that particuar Object.

But the HashTable dont allow theduplicate keyws.

But the NameValueCollection alloes duplicate Keys. as well as it’s provide the fast

way of access to it.

Example HashTable:(It’a raise an error because of the duplicate keys “a”
________________________________________________________________________
Hashtable Ht = new Hashtable();
Ht.Add(“a”, “Object1″);
Ht.Add(“b”, “Object2″);
Ht.Add(“a”, “Object1 Clone”);

Console.WriteLine(Ht["b"]);
Console.WriteLine(Ht["a"]);

Example For NameValueCollection:
________________________________
NameValueCollection col1=new NameValueCollection();
col1.Add(“a”,”Today”);
col1.Add(“a”,”Yesterday”);
col1.Add(“a”,”Tomorrow”);
col1.Add(“b”,”Mango”);
Console.WriteLine((col1.GetValues(col1.Keys[0])[0]).ToString());

This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values under
a single key.

Session Time Out Limit

May 6, 2008

Session Default Time Out is 20 minutes

Maximum we can set up to 4,000  years,,,,,

Session.TimeOut=Minutes.

2,147,483,647

Base 64 Bit Encoding and Decoding

May 6, 2008

string Order = “Ord12011982″;
#region Encode
byte[] Enc = ASCIIEncoding.UTF7.GetBytes(Order);
string EncString = Convert.ToBase64String(Enc);

#endregion
#region Decode
byte[] Dec = Convert.FromBase64String(EncString);
string b = ASCIIEncoding.UTF7.GetString(Dec);
#endregion
Tou can al use UTF8,UTF32

Instead of DataBinder.Eval use DataRowView

May 6, 2008

<%# ((DataRowView)Container.DataItem)["name1"] %>

This One  is the  Best One……..While using DataBinder.Eval()

If your Record exeecds than 100 Rows..It Will become a Problem.More duplication Will Occur.

To Change the GridView Lines Color

May 6, 2008

<asp:DataGrid ID=”DataGrid1″ runat=”server” AutoGenerateColumns=”False”
BorderColor=”Black” BorderStyle=”Solid” BorderWidth=”1px” Width=”300px” PageSize=”7″>
<Columns>
<asp:TemplateColumn ItemStyle-BorderColor=”blue” ItemStyle-BorderStyle=”solid” ItemStyle-BorderWidth=”2px”>
<ItemTemplate>
<center>
<asp:Label ID=”Label1″ runat=”server” Text=’Hello’></asp:Label>
</center>
</ItemTemplate>
<HeaderStyle HorizontalAlign=”Center” />
</asp:TemplateColumn>
<AlternatingItemStyle BackColor=”Gainsboro” BorderColor=”White” />
<HeaderStyle BackColor=”Gray” />
<EditItemStyle BorderColor=”White” />
<ItemStyle BorderColor=”White” />
</asp:DataGrid>

Dynamically Read Assembly File in C#.NET

May 6, 2008

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Web;
using System.IO;
using System.Net;

namespace ConsoleExample
{
class LoadAssembly
{
public void LoadAssembly_FromFile()
{
Assembly Ass = System.Reflection.Assembly.LoadFrom(“D:\\Decisions.Shared.dll”);
Type Asstype = Ass.GetType();

#region Get Constructor Info
ConstructorInfo[] I = Asstype.GetConstructors();
#endregion

#region Extractiong Properties Info
PropertyInfo[] PrInfo = Asstype.GetProperties();
#endregion

#region Extracting Method Info
MethodInfo[] MeInfo = Asstype.GetMethods();
Console.WriteLine(“Return Parameter \t” + MeInfo[0].ReturnType);
Console.WriteLine(“Name \t” + MeInfo[0].Name);
Console.WriteLine(“Module \t” + MeInfo[0].Module);
Console.WriteLine(“Method Body \t” + MeInfo[0].GetMethodBody());
Console.ReadLine();
#endregion

#region Extracting Event Info
EventInfo[] EveInfo = Asstype.GetEvents();
#endregion
Console.ReadLine();
}
}
}

Add Constraints to the Existing Table

May 6, 2008

ALTER TABLE B ADD CONSTRAINT ID2_2  FOREIGN KEY(ID2) REFERENCES DBO.A(ID1)  ON DELETE CASCADE ON UPDATE CASCADE

Aboe:

B->Table Name

ID2_2 -> Foreign Key Name

DBO.A(ID1) -> A-Reference Table.ID1 That table Primary Key

I am implemented cascade delete and Update  while creating the constraints.