Wednesday, October 04, 2006

[.NET 2.0] New Methods / Operator in .NET 2.0

I summarize some of the useful new methods and operator introduced in .NET 2.0 here...

1. String.Contains()

Old way in .NET v1.X
string str = "Today is monday";

if(str.IndexOf("is")!= -1)
// do stuff


New way in .NET 2.0
string str = "Today is monday";
if(str.Contains("is"))
// do stuff


2. String.StartsWith()

Old way
string str = "Alvin Chooi";
if(str.IndexOf("Al")==0)
// do stuff


New way
string str = "Alvin Chooi";
if(str.StartsWith("Al"))
// do stuff


3. String.EndsWith()

Old way
string str = "Alvin Chooi";
if(str.IndexOf("Al")== str.Length-2)
// do stuff


New way
string str = "Alvin Chooi";
if(str.EndsWith("Al"))
// do stuff


4. String.IsNullOrEmpty()

Old way
string str = "Alvin Chooi";
if((str!=null) && (str.Length > 0))
// do stuff


New way
string str = "Alvin Chooi";
if(!String.IsNullOrEmpty(str))
// do stuff


5. TryParse()

Old way
int iValue;
try
{
iValue = Int32.Parse("2x");

return true;
}
catch(Exception ex)
{
return false;
}


New way
int 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");


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



Codes become lesser and lesser... (But why our work will never be lessen?, ha)

7 comments:

dghnfgj said...

I would gold für wow cultivate courage.buy wow gold “Nothing is so mild wow gold cheap and gentle as courage, nothing so cruel and pitiless as cowardice,” syas a wise author. We too often borrow trouble, and anticipate that may never appear.”wow gold kaufen The fear of ill exceeds the ill we fear.” Dangers will arise in any career, but presence of mind will often conquer the worst of them. Be prepared for any fate, and there is no harm to be freared. If I were a boy again, I would look on the cheerful side. life is very much like a mirror:sell wow gold if you smile upon it,maple mesos I smiles back upon you; but if you frown and look doubtful on it,cheap maplestory mesos you will get a similar look in return. Inner sunshine warms not only the heart of the owner,world of warcraft power leveling but of all that come in contact with it. “ who shuts love out ,in turn shall be shut out from love.” If I were a boy again, I would school myself to say no more often.billig wow gold I might cheap mesos write pages maple meso on the importance of learning very early in life to gain that point where a young boy can stand erect, and decline doing an unworthy act because it is unworthy.wow powerleveling If I were a boy again, I would demand of myself more courtesy towards my companions and friends,wow leveling and indeed towards strangers as well.Maple Story Account The smallest courtesies along the rough roads of life are wow powerleveln like the little birds that sing to us all winter long, and make that season of ice and snow more endurable. Finally,maple story powerleveling instead of trying hard to be happy,archlord online gold as if that were the sole purpose of life, I would , if I were a boy again, I would still try harder to make others happy.

game gold said...

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 .

筱娅 said...

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.

mei said...

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.

cheng said...

Do you want to know the magic of online games, and here you can get more angels gold. Do you want to have a try? Come on and angels online gold can make you happy. You can change a lot buy angels gold for play games. And you can use the cheap angels online gold do what you want to do in the online game.
Do you want to know the magic of online games, and here you can get more Rose zuly. Do you want to have a try? Come on and rose zulie can make you happy.You can change a lot rose online zuly for play games. Playing online games can make much rose online zulie. And you can Arua ROSE zuly do what you want to do in the online game.

陈凯燕 said...

Do you know dofus kamas? I like it.
My brother often go to the internet bar to buy kamas and play it.
After school, He likes playing games using these cheap kamas with his friend.
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 dofus gold and play the game with me.
I came to the bar following him and found buy dofus kamas was so cheap. After that, I also go to play game with him.

Do you know eve isk? I like it.
My brother often go to the internet bar to buy eve online isk and play it.
After school, He likes playing games using these buy isk with his friend.
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 eve isk and play the game with me.
I came to the bar following him and found buy eve online isk was so cheap. After that, I also go to play game with him.

feilin said...

My friends and I like to buy habbo credits, because the habbo gold is very useful to upgrade equipment. Only your equipment becomes better, then you can win this game. In habbo coins, you can buy everything you want in this game. Tomorrow will be my birthday, so my friends promise to buy habbo gold as gifts. I am so happy. They understand me so well, cheap habbo credits is my favorite.
I like hero gold very much because it is very useful. In fact at first sight I have fallen in love with hero online gold. So no matter how much I have spent to buy hero gold, I never regret. Because of hero online money, I meet a lot of friends. So I never hesitate to buy hero money.