When a class declares only private instance constructors, it is not possible for classes outside the program to derive from the class or to directly create instances of it. (Except Nested classes)
Make a constructor private if:
*You want it to be available only to the class itself. For example, you might have a special constructor used only in the implementation of your class' Clone method.
*You do not want instances of your component to be created. For example, you may have a class containing nothing but Shared utility functions, and no instance data. Creating instances of the class would waste memory.
Saturday, February 27, 2010
Thursday, February 25, 2010
What is the managed and unmanaged code in .net?
The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier. Compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed execution environment. Code that you develop with a language compiler that targets the runtime is called managed code. it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services.
Difference between DataReader and DataAdapter / DataSet and DataAdapter?
You can use the ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. DataReader can increase application performance and reduce system overhead because only one row at a time is ever in memory.
After creating an instance of the Command object you create a DataReader by calling Command.ExecuteReader to retrieve rows from a data source, as shown in the following example.
SqlDataReader myReader = myCommand.ExecuteReader();
You use the Read method of the DataReader object to obtain a row from the results of the query.
while (myReader.Read())
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
myReader.Close();
DataSet is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source. It can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. DataSet represents a complete set of data including related tables, constraints, and relationships among the tables. The methods and objects in a DataSet are consistent with those in the relational database model. The DataSet can also persist and reload its contents as XML and its schema as XML Schema definition language (XSD) schema.
The DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet. If you are connecting to a Microsoft SQL Server database, you can increase overall performance by using the SqlDataAdapter along with its associated SqlCommand and SqlConnection. For other OLE DB-supported databases, use the DataAdapter with its associated OleDbCommand and OleDbConnection objects.
After creating an instance of the Command object you create a DataReader by calling Command.ExecuteReader to retrieve rows from a data source, as shown in the following example.
SqlDataReader myReader = myCommand.ExecuteReader();
You use the Read method of the DataReader object to obtain a row from the results of the query.
while (myReader.Read())
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
myReader.Close();
DataSet is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source. It can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. DataSet represents a complete set of data including related tables, constraints, and relationships among the tables. The methods and objects in a DataSet are consistent with those in the relational database model. The DataSet can also persist and reload its contents as XML and its schema as XML Schema definition language (XSD) schema.
The DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet. If you are connecting to a Microsoft SQL Server database, you can increase overall performance by using the SqlDataAdapter along with its associated SqlCommand and SqlConnection. For other OLE DB-supported databases, use the DataAdapter with its associated OleDbCommand and OleDbConnection objects.
Saturday, February 20, 2010
Return value from a prompt dialog using Javascript
var choice;
choice= prompt("Choose a number between 1 and 5", "1, 2, 3,4 or 5")
switch (choice)
{
case "1":
alert("You typed in a 1");
break;
case "2":
alert("You typed in a 2");
break;
case "3":
alert("You typed in a 3");
break;
case "4":
alert("You typed in a 4");
break;
case "5":
alert("You typed in a 5");
break;
}
choice= prompt("Choose a number between 1 and 5", "1, 2, 3,4 or 5")
switch (choice)
{
case "1":
alert("You typed in a 1");
break;
case "2":
alert("You typed in a 2");
break;
case "3":
alert("You typed in a 3");
break;
case "4":
alert("You typed in a 4");
break;
case "5":
alert("You typed in a 5");
break;
}
Caching
Caching is a technique widely used to increase performance of the application by keeping the frequently accessed web pages/data in memory.
There are three kinds of caching that can be used by Web applications:
* Output caching
* Fragment caching
* Data caching
Output Caching: increases request/response throughput by caching the content generated from dynamic pages. Every time a page is requested, the subsequent request for that particular page is satisfied by the cache.It is useful where you have static pages.
Syntax :<%@OutputCache Duration="60" VaryByParam="none" %>
@OuputCache is a page directive
Duration parameter specifies how long the HTML output of the Web page should be held in the cache. With the expiration of the duration the cache also become invalid and the ASP.NET Web page then gets generated dynamically, and the cache again gets created with this HTML.
The VaryByParam parameter can be used to cache different views of a dynamic page whose content is generated by GET or POST values.
This type of caching is also known as page level caching.
Fregment Caching: which is also known as partial page level caching allows to cache specific regions of page. Specific regions of your page can be cached with a user control and then @OutputCache directive can be used to cache.The content inside the User Control will be cached for the specified period while the ASP.NET Web page that contains the User Control will continue to serve as a dynamic content.
Data Caching: which is an in-memory cache used for caching objects.The cache is scoped to an application and its lifetime is equivalent to the lifetime of the application.
Caching gives an overall impact on performance of web application.
There are three kinds of caching that can be used by Web applications:
* Output caching
* Fragment caching
* Data caching
Output Caching: increases request/response throughput by caching the content generated from dynamic pages. Every time a page is requested, the subsequent request for that particular page is satisfied by the cache.It is useful where you have static pages.
Syntax :<%@OutputCache Duration="60" VaryByParam="none" %>
@OuputCache is a page directive
Duration parameter specifies how long the HTML output of the Web page should be held in the cache. With the expiration of the duration the cache also become invalid and the ASP.NET Web page then gets generated dynamically, and the cache again gets created with this HTML.
The VaryByParam parameter can be used to cache different views of a dynamic page whose content is generated by GET or POST values.
This type of caching is also known as page level caching.
Fregment Caching: which is also known as partial page level caching allows to cache specific regions of page. Specific regions of your page can be cached with a user control and then @OutputCache directive can be used to cache.The content inside the User Control will be cached for the specified period while the ASP.NET Web page that contains the User Control will continue to serve as a dynamic content.
Data Caching: which is an in-memory cache used for caching objects.The cache is scoped to an application and its lifetime is equivalent to the lifetime of the application.
Caching gives an overall impact on performance of web application.
Wednesday, February 17, 2010
Microsoft Virtual Lab
Learn how to build great applications for Windows and the Web through a series of guided, hands-on labs which can be completed in 90 minutes or less. No need any installation and are available to you immediately for FREE. Start by selecting the lab you’re interested in .Check this url.
http://msdn2.microsoft.com/hi-in/virtuallabs/default(en-us).aspx
http://msdn2.microsoft.com/hi-in/virtuallabs/default(en-us).aspx
Monday, February 8, 2010
Reverse a string.
string str = "This is the string which we have to revert";
char[] step1 = str.ToCharArray();
Array.Reverse(step1);
Console.WriteLine("Original string:" + str);
Console.WriteLine("Reverse of a string:" + new string(step1));
char[] step1 = str.ToCharArray();
Array.Reverse(step1);
Console.WriteLine("Original string:" + str);
Console.WriteLine("Reverse of a string:" + new string(step1));
Subscribe to:
Posts (Atom)