Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,092 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,809 people online right now. Registration is fast and FREE... Join Now!




Difference between Clear() and String.Empty or =""

2 Pages V  1 2 >  
Reply to this topicStart new topic

Difference between Clear() and String.Empty or ="", What's the difference with these methods when clearing a textbox?

Locuranis
21 Jun, 2008 - 01:23 PM
Post #1

New D.I.C Head
*

Joined: 14 Jun, 2008
Posts: 9

Hello. I'm hoping someone can explain this to me as I'm not sure I understand the difference. I turned in an assignment last week but my instructor said I "should have used clear() for the textboxes". I used ="" I've heard that String.Empty is the same as ="", though I'm not sure. So I'm wondering what (if any) is the fundamental difference with using TextBox1.Clear(), Textbox1.Text = "", or Textbox1.Text = String.Empty.

If there's a major difference in how these methods operate, then I'd like to understand. I just want to be sure it's not a case of someone teaching their preferred method if there's no benefits of difference. Thanks!
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Difference Between Clear() And String.Empty Or =""
21 Jun, 2008 - 01:51 PM
Post #2

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,262



Thanked: 39 times
Dream Kudos: 1675
My Contributions
Well, i am positive String.Empty() and "" are identical. I also think that TextBox.Clear() is the same as the other two. At the very least, they all produce the same result, which is an empty string (""). In my opinion, unless your instructor said specifically to use TextBox.Clear(), i don't think he should of thought anything of it.
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Difference Between Clear() And String.Empty Or =""
21 Jun, 2008 - 04:22 PM
Post #3

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
As jacobjordan said, they are all identical. But if I were to be clearing a TextBox, I would personally choose the TextBox.Clear() method as it is more .NET standard compliant then "". If Clear wasn't available then I'd use String.Empty (again, a member of the .NET framework).

They all do the same thing, but if unconventional methods are being used when there is a method more conventional, it would be better to use to the more conventional way to ensure you have sustainable code.

Hope that helps. smile.gif

EDIT: Also, another advantage of using the .NET framework more often is that porting to simular .NET based languages such as C# is much easier. wink2.gif

This post has been edited by RodgerB: 21 Jun, 2008 - 04:51 PM
User is offlineProfile CardPM
+Quote Post

Locuranis
RE: Difference Between Clear() And String.Empty Or =""
21 Jun, 2008 - 06:00 PM
Post #4

New D.I.C Head
*

Joined: 14 Jun, 2008
Posts: 9

Thanks for the info. I just wanted to know if there was in fact any sort of difference in using one over another.
User is offlineProfile CardPM
+Quote Post

narmer93
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 12:57 AM
Post #5

D.I.C Regular
***

Joined: 13 Mar, 2008
Posts: 253



Thanked: 2 times
My Contributions
QUOTE("RodgerB")
EDIT: Also, another advantage of using the .NET framework more often is that porting to simular .NET based languages such as C# is much easier.

do u mean c#doesn't need .netframework as vb.net,
so ican send c# projecs to friends and they will work even if they have .netframework installed?
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 01:22 AM
Post #6

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
QUOTE(narmer93 @ 22 Jun, 2008 - 06:57 PM) *

do u mean c#doesn't need .netframework as vb.net,
so ican send c# projecs to friends and they will work even if they have .netframework installed?


A C# application will work the same way as a VB.NET application does (kinda, but very similar), so a C# application will require the .NET framework be installed.
User is offlineProfile CardPM
+Quote Post

narmer93
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 04:37 AM
Post #7

D.I.C Regular
***

Joined: 13 Mar, 2008
Posts: 253



Thanked: 2 times
My Contributions
is there any other programming language that doesn't need .netframework?
User is offlineProfile CardPM
+Quote Post

WayneSpangler
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 06:41 AM
Post #8

D.I.C Head
**

Joined: 22 Mar, 2008
Posts: 103



Thanked: 9 times
My Contributions
As far as the question on clearing a textbox In one of my books it stated, "you do what the person paying you or giving out the grades says you do." You can do what you want on your own projects.


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 06:53 AM
Post #9

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE(narmer93 @ 22 Jun, 2008 - 05:37 AM) *

is there any other programming language that doesn't need .netframework?


There are tons of languages that dont need the .Net Framework: C++, Java, Perl, Pascal, C, Ruby, Python, etc smile.gif

User is offlineProfile CardPM
+Quote Post

narmer93
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 01:03 PM
Post #10

D.I.C Regular
***

Joined: 13 Mar, 2008
Posts: 253



Thanked: 2 times
My Contributions
isn't java a progragramming language for the internet,and what programme do i need for it?
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 01:43 PM
Post #11

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You're thinking of JavaScript, which is completely different from Java. Java is a programming language, JavaScript is a client-side scripting language smile.gif
User is offlineProfile CardPM
+Quote Post

narmer93
RE: Difference Between Clear() And String.Empty Or =""
22 Jun, 2008 - 01:44 PM
Post #12

D.I.C Regular
***

Joined: 13 Mar, 2008
Posts: 253



Thanked: 2 times
My Contributions
what is the programming programme that i need to use it?
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:03AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month