There are some function in vb but not in c#

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

Why there are some function about strings in vb.net but not in c#.
Like right, InStr...
Can we use the VB.NET function in C#
 
InStr in VB is equivalent to IndexOf in C#.

You can use .Substring() and .Length with a little math to get the same
effect as RIght in VB.

You can also check the Microsoft.VisualBasic namespace, which I believe
will allow you to call VB functions from C#.

That said, IMHO it's awful style to call VB functions from C# or vice
versa. VB.NET is VB.NET. C# is C#. If you're trying to program C# and
make it look like VB, or vice versa, then you really should give your
head a shake.

Learn the language you're working in and program using that idiom. If
you start calling VB functions from C# you'll just produce code that
later programmers (trying to do maintenance) won't understand. Bad
form, IMHO.
 
Those functions support legacy VB6 code. For the most part they duplicate
functionality already available in the .NET framework -- often with evil
little twists that can introduce subtle problems. When I have to work on
VB.NET code, I use the same framework support I use in C#. Any .NET
programmer should know how to use the methods of the string class, such as
IndexOf(), but only a VB developer would know about Instr().

That is the perspective of a person whose primary language is C# and who
does not have much of a legacy VB background, aside from VBScript. On the
other hand, a VB6 developer who liked VB6 often tends to approach VB.NET
from the perspective of changing their coding habits as little as humanly
possible. This is arguably a legitimate point of view, although I'd say
it's a rather narrow and parochial one, and therefore short-sighted. But
when it comes to C# (or any other .NET language) it's definitely
inappropriate to borrow VB compatibility syntax. Each language is what it
is, and if you don't like what it is, you shouldn't use it at all. Besides,
you don't want to write code that only a person who has a background in both
C# and VB.NET could figure out.

--Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top