Visual studio 2010 is great IDE and i am discovering everyday some thing new. Today i have discovered one of fantastic option to increase performance of your visual studio IDE. Visual Studio 2010 has option when we enabled it it will automatically adjust the visual and client experience as per your hardware configuration. It will increase the performance of visual studio and productivity in lower hardware also. You can find that checkbox under Tools->General-> Automatically adjust visual experience based on client performance. There are two checkbox is given one for above and another for Rich User Experience but they may decrease your visual studio performance. Like following.
Indexer class in C#
While taking interviews for Microsoft.NET i often ask about indexer classes in C#.NET and i found that most of people are unable to give answer that how we can create a indexer class in C#.NET. We know the array in C#.NET and each element in array can be accessed by index same way for indexer class a object was class can be accessed by index. Its very easy to create a indexer class in C#. First lets looks some points related to indexer class in C#.
- Indexer class object can be accessed by index only.
- We can use same mechanism to access object of indexer class as we are doing it for array.
- You can can specify any valid C# type as return type of indexer classes.
- You must have to create a property with parameter using this keyword for indexer class.
- You can also implement multi parameter indexer also.
Let’s create simple indexer class with single parameter and for string type.
public class MyIndexer
{
private string[] MyIndexerData;
private int SizeOfIndexer;
//declaring cursor to assing size of indexer
public MyIndexer(int sizeOfIndex)
{
this.SizeOfIndexer = sizeOfIndex;
MyIndexerData = new string[SizeOfIndexer];
}
public string this[int Position]
{
get
{
return MyIndexerData[Position];
}
set
{
MyIndexerData[Position] = value;
}
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int indexSize=5;
MyIndexer objMyIndexer = new MyIndexer(indexSize);
for (int i = 0; i < indexSize; i++)
{
objMyIndexer[i] = i.ToString();
Console.WriteLine("Indexer Object Value-[{0}]: {1}",
i, objMyIndexer[i]);
}
Console.ReadKey();
}
}
}
Technorati Tags: Indexer,C#,Array
Microsoft.NET 4.0/VB.NET 10 Automatic Properties
In C# we are having automatic properties since C# 3.5 framework but now with Microsoft.NET 4.0 Framework VB.NET 10.0 version we are also having automatic properties for VB.NET Also.
Like in C# we can define automatic like following.
Public string TestProperty
{
get;
set;
}
Public Property TestProperty As String
ASP.NET and Load balancing.
In one of our project the site usage of site was very heavy and we need to migrate it to load balancing server. I have never configured the sites in the load balancing server but it was quite interspersing experience Here are the some points which we need to take care while we move asp.net sites into the load balancing environments. So first we will see what is load balancing.
Following is a load balancing definition from the Google.
In computer networking, load balancing is a technique to distribute workload evenly across two or more computers, network links, CPUs, hard drives, or other resources, in order to get optimal resource utilization, maximize throughput, minimize response time, and avoid overload.
Following are the points which you need to take care when you are deploying your asp.net sites into load balancing server environments.
Machine Key Should be same for both servers: View state and session both are depends on the machine key. If you machine key is not same then you will have problems related to session and view state you may loose your session and view state in between request during post backs. If machine key will not be same then its possible that you can get strange result in Ajax requests. There is a machine key section in web.config where you can specify machine key.
<machineKey validationKey='C44B8B7C521CB5BC7E602BAE6118AA44CD690C7304817129DA27C17E800132A1BD946C6D9AD12F0A5B342840C7D130564195428160B7466146938CA9E3A62686' decryptionKey='0E9DF2DA7F210B84087690FF0BF25C905182AD81E16A5FA9' validation='SHA1'/>
Following is a good link to learn how you can configure sessions state in asp.net application.
And here is a good link to configure session on SQL Server.
http://support.microsoft.com/kb/317604
<sessionState mode="SQLServer" StateConnectionString="tcpip=127.0.0.1:42424" SqlConnectionString = "data source=SERVERNAME; user id=sa; password=sa" cookieless="false" timeout="20" />
<system.web> <pages enableViewStateMac="false" /> </system.web>
http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx
http://forums.asp.net/p/1119925/1881331.aspx#1881331
File Replication:File Replication is also an important features of load balancing you should have replication enabled on the folders of web application so if you upload anything on one server it should replicated to other sites. Following is good link to understand file replication.
Sticky Sessions: In some scenario Sticky session is very useful. In one page our application we have used extensive Ajax and we need that for each request and partial post back it should stay on one server till request completes.To achieve that we can used sticky session. Following are some good links to know about sticky sessions.
http://dev.fyicenter.com/Interview-Questions/JavaScript/What_does_the_term_sticky_session_mean_in_a_web_.html
http://blogs.msdn.com/drnick/archive/2007/07/13/sticky-sessions.aspx
Hope this will help you on deploying your asp.net on load balancing sites. Following are some good links for understanding load balancing in more details
http://technet.microsoft.com/en-us/library/bb742455.aspx
http://support.microsoft.com/kb/323437
http://technet.microsoft.com/en-us/library/cc754833%28WS.10%29.aspx.
http://edge.technet.com/Media/Network-Load-Balancing-NLB-in-Windows-Server-2008/
Rename feature in Visual Web Developer 2010/Visual Studio 2010
Visual web developer is great tool and I am playing more and more with it and every time I am discovering some new features of it. Recently I have discovered a very cool feature of it. I want to rename a variable in visual studio 2010 Web Developer express edition and I found a great refractor tool for that which will rename that variable in all the instance and all the methods. First you need to select variable which you want to rename and then you need to Right Click ->Refractor->Rename. You can also invoke that via its shortcut Ctrl + R,Ctrl +R and it will be available For reference see the below screenshot.
Once you click the rename which will have a dialog box open which will ask for new name or variable like following.
It is also having options for search in comments and search in string. Search in comment will search and replace in comment and search in string will replace word for any string which contains that variable name. Once you put new name in dialog box it will display a preview of replaced strings like following. Here also you can select where you need to rename and where you don’t want to rename and this is really cool. :)
