Events are similar to properties.
Both of them are declared to be of certain type,which in case of an event it is forced to be delegate type,The reason for having events in the first place is very much like the reason for having properties.
Wednesday, August 10, 2011
Tuesday, August 9, 2011
Difference between Delegate and MulticastDelegate?
What is delegate?
A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.
What is Multicast delegates?
Multicast delegates nothing more than normal delegates that have multiple method references in their invocation list
Note:delegate and multicast delegates are not two types of delegates it is the way we are implementing delegates if we assigned only one method it is single cast if more methods its multicast like wise.
A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.
What is Multicast delegates?
Multicast delegates nothing more than normal delegates that have multiple method references in their invocation list
Note:delegate and multicast delegates are not two types of delegates it is the way we are implementing delegates if we assigned only one method it is single cast if more methods its multicast like wise.
Monday, February 21, 2011
ADO.NET - Generic Programming Model
We are usually writing code for handling databases, specific to any database like sql server, oracle etc. how we can write code with out specifying the database or code that suite for any database provider?. yes it is possible by using the class DbProviderFactory.
lets see how we can use dbproviderfatory to make database layer for our program.
for example :if we are using sql server and c# then our database specific code will be like this
//NameSpace
using System.Data.SqlClient;
//Code
SqlConnection con = new SqlConnection();
con.ConnectionString = "Your Connection String";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Your Command Text";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
we can write a database specific code for mysql like this
//NameSpace
using MySql.Data .MySqlClient ;
//Code
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "Your Connection String";
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "Your Command Text";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
how we can generalize our code, by using dbproviderfatory . to better understand this class you should have an idea about provider factory and abstract factory design pattern.
Just read articles in references for more info
ok. then how we can implement this:
//NameSpace
using System.Data.Common;
//Code
DbProviderFactory oProviderFactory;
DbConnection con;
oProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
//oProviderFactory = DbProviderFactories.GetFactory("System.Data.MySqlClient") 4 MySQL
Con = oProviderFactory.CreateConnection;
Con.ConnectionString = "Your Connection String";
DbCommand cmd = con.CreateCommand();
cmd.CommandText ="Your Command Text";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
It is always better to go for generic programming model you can easily switch to any database later.
References:
Generic Coding with the ADO.NET 2.0 Base Classes and Factories
Writing Generic Data Access Code in ASP.NET 2.0 and ADO.NET 2.0
Abstract Factory Design Pattern in ADO.NET 2.0
It is always better to go for generic programming model you can easily switch to any database later.
References:
Generic Coding with the ADO.NET 2.0 Base Classes and Factories
Writing Generic Data Access Code in ASP.NET 2.0 and ADO.NET 2.0
Abstract Factory Design Pattern in ADO.NET 2.0
Subscribe to:
Comments (Atom)