I just got back from MVP summit from Seattle, and there were lots of new and cool stuff about the future of .NET and web development with vNext. I would strongly to suggest that you join the virtual developer Microsoft conference Connect(); http://www.visualstudio.com/en-ca/connect-event-vs On the 12th you will have keynotes from Scott Gu, Scott Hanselman […]
Here is a quick C# tip, when using string compare don’t use
|
1 2 3 |
var str = "Hello"; if(str.ToLower() === "hello") |
use the Equals and StringComparison.InvariantCultureIgnoreCase enum.
|
1 2 3 |
var str = "Hello"; if(str.Equals("hello", StringComparison.InvariantCultureIgnoreCase)) |
The thing you need to note is which rules are appropriate current culture, the invariant culture, ordinal or another culture entirely. One can create the compare from StringComparer.Create(culture, true)
Node Tools for Visual Studio is currently in Alpha 1.0 and its free and opensource, in this post I will show you how to install Node and Node Tools for Visual Studio (NTVS). First lets install Node.js Download Node from http://nodejs.org/ The currently version is node-v0.10.26-x64 Step one lets run the msi that we just […]
Here is another C# tip. Most of the time when you are trying to get a value from dictionary you would try to check if the key exist or not something like.
|
1 2 3 4 5 6 |
if(dictionary.ContainsKey(key)) { var value - dictionary[key]; //do some stuff } |
But one can use TryGetValue
|
1 2 3 4 |
if(dictionary.TryGetValue(key, out value)) { //do stuff with value } |
The benefit of using TryGetValue is that the dictionary is synchronized, there is no race condition.
If you are running Windows Server 2012 with IIS8 and you got this error HTTP Error 500.19 – Internal Server Error. If you web.config file contains “handler” or “modules” tag. In order to fix this, launch cmd or powershell and execute these 2 commands inside of C:\Windows\System32\InetSrv
|
1 2 3 |
PS C:\Windows\System32\InetSrv>.\appcmd.exe unlock config -section:system.webServer/handlers PS C:\Windows\System32\InetSrv> .\appcmd unlock config -section:system.webServer/modules |
This will unlock the handlers and modules […]
In C# there is a params keyword which allows a method parameter to take variable number of arguments. MSDN Some notes on param It must always be the last parameter in the function/method definition There can only be one params keyword in a function/method parameter signature Example:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
int Sum(int[] args) { int sum = 0; foreach (var item in args) { sum += item; } return sum; } //calling the above Sum method we would call it like int[] array = new int[] {1, 2, 3} int result = Sum(array); |
But by changing it to params we […]
In C# there is the out parameter keyword which causes arguments to be passed by reference. It is like the ref keyword, except that ref requires that the variable be initialized before it is passed. Example:
|
1 2 3 4 5 6 7 8 9 10 |
void Init(out int x) { x = 47; } int x; Init(out x); Console.WriteLine(x); //x now is 47 |
The out parameter keyword provides a way for a method to output multiple values from a method without […]
In C# when using the ref keyword it causes an argument to be passed by reference, not by value. In order to use a ref as a parameter, both the method definition and the calling method must explicitly use the ref keyword, and also the variable must be initialized before passing in. In the example […]




