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:\\Parthiban\\ConsoleExample\\CrystalDecisions.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 = [...]
Archive for the 'C#.NET' Category
To Read a Assembly file using Reflection in C#.NET
July 20, 2008Passing Object Reference to a Function
July 20, 2008While Passing reference to the function any changes made to that variables inside the Function.That will affect the
Main variable value.
—————————————–
When we can Pass it object value as variables it just make a Copy of that variables…… and than it takes to perform
an operation.But while passing the reference Both variables are refer to the same memory [...]
Overloaded Constructor in C#.NET
July 20, 2008A class can have any number of constructor.
OverloadConstructor is nothing but the Constructor having different set of parameters.
1.Under this type of situation ,how to call one Constructor to another constructor.
For the below Example when creating Object to the Parameter 2 Constructor it automatically redire
-ct to the Parameter 3 Constructor.The Parameter 2 Constructor wont’t called
///////////////////////////////////////////////////////////////////////////////////////////
using System;
using [...]
To Call a Base Class Constructor From Derived Class Constructor Calling in C#.NET
July 20, 2008class CheckStatic:NewKeyWord
{
public CheckStatic():base()
{
Console.WriteLine(“I am a Derived Class Constructor”);
}
public void CheckStatic1()
{
base.GetData1();
}
}
///////////////////////////////////////////
Use the (Base) Keyword to call a Base Class Constructor.
Basic 64-bit Encoding and Decoding in C#.NET
July 20, 2008byte[] Keybyte = new byte[Key.Length];
System.Text.ASCIIEncoding Encoding = new System.Text.ASCIIEncoding();
return Convert.ToBase64String(Encoding.GetBytes(Key) );
///// U can also use it to convert string to Bytes.
Short Method:
string OrderCode = “Ord12011982″;
#region Encode
byte[] Enc = ASCIIEncoding.UTF7.GetBytes(OrderCode);
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
Transaction in C#.NET
July 20, 2008SqlConnection conn = new SqlConnection(connString);
SqlTransaction trans = conn.BeginTransaction();
try
{
SqlCommand cmd = new SqlCommand(“MyWriteProc”,conn, trans);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(….
…
// additional transactioned writes to database
trans.Commit();
}
catch
{
trans.Rollback();
}
When you use ADO.NET manual transactions, you can set the desired isolation
level on the BeginTransacion method as shown in the following code fragment.
SqlConnection conn = new SqlConnection(connString);
SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
Using Block inside the void Main in c#.NET,ASP.NET
July 20, 2008We 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, 2008using 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 [...]
Variable Passing in C#.Net
July 20, 2008class 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, 2008The 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 = [...]