Subscribe to Subscribers
Talk to Webmaster Tony John


Forums » .NET » General »

Need clarification to declare a variable.


Posted Date: 10 Aug 2012      Posted By:: Balamurali     Member Level: Silver    Member Rank: 0     Points: 2   Responses: 2



Hi all,

I would like to know which of the following is best and why?

1. Dim sName As String = String.Empty

2. Dim sName = String.Empty (Implicit convertion)




Responses

#683842    Author: Pawan Awasthi      Member Level: Diamond      Member Rank: 4     Date: 10/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

Hai Bala,
See the inline comments of your query:
1. Dim sName As String = String.Empty
Here the variable is declared with the type and then initialized. So if this variable is used further then there is no need to convert it to the respective type as it is already of string type.

2. Dim sName = String.Empty (Implicit convertion)
In this case, the variable is not having any type and initialized with the string variable. So when used, you need to convert it in to respective type and then you can use it. So here it will consume more cpu cycles and performance wise it will be slow as it need to first type cast and use it.
Hope it will be helpful to you.

Regards,
Pawan Awasthi(DNS MVM)
+91 8143683708 (pawansoftit@gmail.com)
Outstanding Contribution Award..NTT Data Inc



 
#684035    Author: Ajesh Madhukar Dalvi      Member Level: Silver      Member Rank: 340     Date: 12/Aug/2012   Rating: 2 out of 52 out of 5     Points: -1

[Response removed by Admin for invalid response to the thread or violation of forum policies.]


 
Post Reply
You must Sign In to post a response.

Next : Tips And Tricks All Time Need For Your Computer
Previous : Very happy Gokulashtami to all my Indian friends
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.