It seems I am posting after so many days!!!
I have just started playing with VS 2010 and started to find out so many cool inclusions.
Here are few of them… I will keep rolling this post – anybody wants to add to the ever growing list is most welcome… J
.Net 4.0 Newbie => SortedSet and StringBuilder.Clear() | Here comes our sorted list: 1 2 3 4 5 6 7 8 9 | |
.Net 4.0 Newbie => String.IsNullOrWhiteSpace(param) | New method has discoverd WhiteSpace in param | |
.Net 4.0 Newbie => Stopwatch.Restart() | Elapsed Time in mSec Before Stopwatch Restarted = 5 | |
.Net 4.0 Newbie => String.Concat | MNOPQRSTUVWXYZ |
The sample code is given below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Diagnostics;
namespace LearningDotNet4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var sSet = new SortedSet<int> { 2, 4, 6, 8, 9, 1, 3, 5, 7 };
var sBulder = new StringBuilder();
sBulder.Append("Here comes our sorted list: ");
//Getting directly the sorted output
foreach (int iVal in sSet)
{
string strVal = iVal.ToString();
sBulder.Append(strVal + '\t');
}
Label2.Text = sBulder.ToString();
sBulder.Clear();
String strData = " ";
sw.Start();
for (int i = 0; i < 1000000; i++)
{//Do something
//....
//ERROR!!!}
Label6.Text = "Elapsed Time in mSec Before Stopwatch Restarted = " + sw.ElapsedMilliseconds.ToString();
//Restart the Stopwatch
sw.Restart();
string output = String.Concat(GetAlphabet(true).Where(letter => letter.CompareTo("M") >= 0));
Label8.Text = output;
}
private static List<string> GetAlphabet(bool upper)
{List<string> alphabet = new
List<string>();
int charValue = upper ? 65 : 97;
for (int ctr = 0; ctr <= 25; ctr++)
alphabet.Add(Convert.ToChar(charValue + ctr).ToString());
return alphabet;
}
}
}
if (String.IsNullOrWhiteSpace(strData)){Label4.Text = "New method has discoverd WhiteSpace in param";}
Stopwatch sw = new Stopwatch();
No comments:
Post a Comment