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!
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!
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.
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.
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.
This post has been edited by RodgerB: 21 Jun, 2008 - 04:51 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.
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.