1. String.Contains()
Old way in .NET v1.X
string str = "Today is monday";
if(str.IndexOf("is")!= -1)
// do stuff
if(str.IndexOf("is")!= -1)
// do stuff
New way in .NET 2.0
string str = "Today is monday";
if(str.Contains("is"))
// do stuff
if(str.Contains("is"))
// do stuff
2. String.StartsWith()
Old way
string str = "Alvin Chooi";
if(str.IndexOf("Al")==0)
// do stuff
if(str.IndexOf("Al")==0)
// do stuff
New way
string str = "Alvin Chooi";
if(str.StartsWith("Al"))
// do stuff
if(str.StartsWith("Al"))
// do stuff
3. String.EndsWith()
Old way
string str = "Alvin Chooi";
if(str.IndexOf("Al")== str.Length-2)
// do stuff
if(str.IndexOf("Al")== str.Length-2)
// do stuff
New way
string str = "Alvin Chooi";
if(str.EndsWith("Al"))
// do stuff
if(str.EndsWith("Al"))
// do stuff
4. String.IsNullOrEmpty()
Old way
string str = "Alvin Chooi";
if((str!=null) && (str.Length > 0))
// do stuff
if((str!=null) && (str.Length > 0))
// do stuff
New way
string str = "Alvin Chooi";
if(!String.IsNullOrEmpty(str))
// do stuff
if(!String.IsNullOrEmpty(str))
// do stuff
5. TryParse()
Old way
int iValue;
try
{
iValue = Int32.Parse("2x");
return true;
}
catch(Exception ex)
{
return false;
}
try
{
iValue = Int32.Parse("2x");
return true;
}
catch(Exception ex)
{
return false;
}
New way
int iValue
bool isValid = Int32.TryParse("2x",out iValue);
bool isValid = Int32.TryParse("2x",out iValue);
6. Non-null operator (??)
Old Way
string str = null;
if(str!=null)
Response.Write(str);
else
Response.Write("It is null");
if(str!=null)
Response.Write(str);
else
Response.Write("It is null");
New way
Response.Write(str?? "It is null");
7. Eval() & Bind() in ASP.NET 2.0
Old way
<%# DataBinder.Eval(Container.DataItem,"MyField") %>
New way
<%# Eval("MyField") %> // one-way binding
<%# Bind("MyField") %> // two-way binding
<%# Bind("MyField") %> // two-way binding
Codes become lesser and lesser... (But why our work will never be lessen?, ha)
3 comments:
To buy cabal online alz , it is not the aim of the cable. It is the game which brings a lot of happiness to me. We buy the cabal alz together. The beautiful story, we can not be forgotten, buy cabal alz . You will not regret to have cabal gold . So I will continue to have cabal money , it is a beautiful fairy tale, it looks like my life.
On account of I have fiesta Gold , I am not afraid of the lonely. At that time I do not know the meaning of it. Later I buy fiesta money . And every time, I have no fiesta online gold , I will feel very anxious. Why I buy fiesta Gold , please it gives me such a warm place. At the moment, I have fiesta online money .
Have you heared about a game which you need use Anarchy credits to play, and you can also borrow Anarchy Online credits from other players? But you can buy AO credits, or you will lose the choice if you do not have Anarchy online gold. If you get Anarchy gold, you can continue this game.
Have you heared about 9Dragons which you need use 9Dragons gold to play, and you can also borrow 9 Dragons gold from other players? But you can buy 9 Dragons gold, or you will lose the choice if you do not have cheap 9Dragons gold. If you get 9Dragons money, you can continue this game.
Do you know latale online gold? I like it.
My brother often go to the internet bar to buy latale gold and play it.
After school, He likes playing games using these latale money with his friends.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many buy latale online gold and play the game with me.
I came to the bar following him and found cheap latale gold was so cheap. After that, I also go to play game with him.
Do you know seal cegel? I like it.
My brother often go to the internet bar to buy sealonline cegel and play it.
After school, He likes playing games using these seal online cegel with his friends.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many cheap seal cegeland play the game with me.
I came to the bar following him and found buy seal online cegelwas so cheap. After that, I also go to play game with him.
Post a Comment