473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Difference between C# and VB.NET

Hi Guys,

It might seem to be a very easy question, but i am very much eager to
know some good technical difference between C# and VB.NET.

Are there anything that i can do in one language and cannot in other?
And finally why C# seems to be a sort of standard in industry?

Regards,
Raj Dhrolia.
Nov 15 '05 #1
11 3585
Yes, a good question.

For example are there differences in

- implicit/explicit conversions
- user-defined operators

?

i just haven't look at vb so maybe a quick guide could be provided by
someone
to help us avoid digging in vb specification?
Nov 15 '05 #2
> Are there anything that i can do in one language and cannot in other?

For example, in VB .NET a single class method can implement several
interface methods. This trick, as fas as I know, is not possible in C#. In
fact, most of the differences between the languages are subtleties like this
one. I think there is no fundamental task you can do in one language and
cannot in the other.
And finally why C# seems to be a sort of standard in industry?
I think because it has been initially designed for .NET while VB.NET is
rather an improvement to VB6.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Raj Dhrolia" <ra********@hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl... Hi Guys,

It might seem to be a very easy question, but i am very much eager to
know some good technical difference between C# and VB.NET.

Are there anything that i can do in one language and cannot in other?
And finally why C# seems to be a sort of standard in industry?

Regards,
Raj Dhrolia.


Nov 15 '05 #3
Dmitriy Lapshin [C# / .NET MVP] wrote:
For example, in VB .NET a single class method can implement several
interface methods. This trick, as fas as I know, is not possible in
C#.


I don't understand this statement. C# classes can implement more than
one interface and the methods contained therein so obviously you're
talking about something else.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
I mean the following construct:

In VB .NET:

Private Sub DoSomething() Implements IFirst.DoSomething, ISecond.DoSomething

In C# we can only:

void IFirst.DoSomething()
void ISecond.DoSomething()

if we do not want to expose the DoSomething() method as a part of the public
class interface.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:e7**************@TK2MSFTNGP11.phx.gbl...
Dmitriy Lapshin [C# / .NET MVP] wrote:
For example, in VB .NET a single class method can implement several
interface methods. This trick, as fas as I know, is not possible in
C#.


I don't understand this statement. C# classes can implement more than
one interface and the methods contained therein so obviously you're
talking about something else.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


Nov 15 '05 #5
I would add Indexers. For example when you do this

Row("FieldName")="jajaja"
this is the .ITEM property of DataRow class. And this property is indexed by
a "Key". Indexers are available only in C#
In VB you should make a GetByKey method.

And in C# there is no
with object
...
end with

"Alexander Nenashev" <ne******@hotbox.ru> escribió en el mensaje
news:#T*************@TK2MSFTNGP11.phx.gbl...
Yes, a good question.

For example are there differences in

- implicit/explicit conversions
- user-defined operators

?

i just haven't look at vb so maybe a quick guide could be provided by
someone
to help us avoid digging in vb specification?

Nov 15 '05 #6
You certainly can do indexers in VB. Have you tried the Default keyword? In
fact, you can have named indexers, since all properties can take parameters.
While I wouldn't call this a "limitation" of C#, it is true that VB does
MORE than C# in this respect.

Matthew W. Jackson

"Osvaldo Bisignano" <va*************@yahoo.com.ar> wrote in message
news:Oh**************@TK2MSFTNGP09.phx.gbl...
I would add Indexers. For example when you do this

Row("FieldName")="jajaja"
this is the .ITEM property of DataRow class. And this property is indexed by a "Key". Indexers are available only in C#
In VB you should make a GetByKey method.

And in C# there is no
with object
...
end with

"Alexander Nenashev" <ne******@hotbox.ru> escribió en el mensaje
news:#T*************@TK2MSFTNGP11.phx.gbl...
Yes, a good question.

For example are there differences in

- implicit/explicit conversions
- user-defined operators

?

i just haven't look at vb so maybe a quick guide could be provided by
someone
to help us avoid digging in vb specification?


Nov 15 '05 #7
Actaully, VB supports Properties with arguments, which is in fact, far more
flexible than Indexers - because you can have more than one per class for
starters.
To create a simple Indexer, just use the VB Default keyword on the property
and have at least one property argument.

-Rob Teixeira [MVP]

"Osvaldo Bisignano" <va*************@yahoo.com.ar> wrote in message
news:Oh**************@TK2MSFTNGP09.phx.gbl...
I would add Indexers. For example when you do this

Row("FieldName")="jajaja"
this is the .ITEM property of DataRow class. And this property is indexed by a "Key". Indexers are available only in C#
In VB you should make a GetByKey method.

And in C# there is no
with object
...
end with

"Alexander Nenashev" <ne******@hotbox.ru> escribió en el mensaje
news:#T*************@TK2MSFTNGP11.phx.gbl...
Yes, a good question.

For example are there differences in

- implicit/explicit conversions
- user-defined operators

?

i just haven't look at vb so maybe a quick guide could be provided by
someone
to help us avoid digging in vb specification?


Nov 15 '05 #8

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:uF**************@tk2msftngp13.phx.gbl...
Are there anything that i can do in one language and cannot in other?

For example, in VB .NET a single class method can implement several
interface methods. This trick, as fas as I know, is not possible in C#. In
fact, most of the differences between the languages are subtleties like this one. I think there is no fundamental task you can do in one language and
cannot in the other.


There are a few things each can do that the other can't (and I suppose you
can argue about how "fundamental" these things are). At the moment, VB can't
overload operators and can't use unsigned types natively (it can use the
primitive unitXX classes, for example, but not directly like their signed
cousins) - this one in particular is fairly odd, considering that VB
recently introduced shift operators. Also, VB can't directly manipulate
pointers without the help of classes in the system.runtime.interop namespace
and GC handles to pinned references (although to be fair, C# also requires
pinned references, though the syntax is slightly different).

At any rate, with the next version of VS, VB will be able to handle all
these features except the direct pointer manipulation AFAICT. Do note
however, that direct pointer manipulation is not considered part of the core
CLI, and must be marked as Unsafe code. However, VB can still manipulate
pointers, so in this case, it's not as if it can't be done, it will just be
different.
And finally why C# seems to be a sort of standard in industry?


I think because it has been initially designed for .NET while VB.NET is
rather an improvement to VB6.


Actually, if memory serves, C# was going to be an independant project, and
then got merged/morphed into the Common Language specs/framework as well.
However, as you mentioned, unlike VB, C# has no clear and direct
predicessor. It's another "C-like" language.

I'm not sure what the original poster means by industry standard. I'm
willing to wager there is far more code in VB than C# at the moment -
especially if you concider older VB/VBScript/ASP code and migrations
thereof. Fundamentally, if you are using .NET, you writing IL code. The
syntax that gets you to the IL (whether it's VB, C#, FORTRAN, or even COBOL)
is in essance slightly less relevant. So basically, instead of doing what
Sun did with Java - which was to create ONE master language everyone had to
learn - the .NET team gave programmers a choice of syntax. If the programmer
is more familiar with VB, then VB.NET will be his best choice to enter the
..NET world, while other programmers who are more familiar with Java/C/C++
will find it easier to use C#. As always, I recommend that everyone learn
both - they aren't entirely different, and the hardest part is learning the
framework (which they both share). This will make you a far more valuable
resource, and doesn't take much effort.

One thing to note in addition is that C# has been submitted to international
standards - which means that others can write their own implementation of C#
based on the official specification. VB.NET, on the other hand, is
proprietary property of MS. But that's about the only "standard" that you
can concretely quantify.

-Rob Teixeira [MVP]
Nov 15 '05 #9
<"Rob Teixeira [MVP]" <RobTeixeira@@msn.com>> wrote:
Actaully, VB supports Properties with arguments, which is in fact, far more
flexible than Indexers - because you can have more than one per class for
starters.


You can have more than one indexer per class in C#. You just can't have
more than one indexer with the same parameters signature.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10
You can have only one indexer in C#, though it can be overloaded.
That's not quite the same thing as having multiple (differently named)
properties with arguments in the same class.

You have to remember that properties in the CLI are actually methods (two
methods for each property if they are read/write) with a special meta tag
that makes them a property. In addition, one of those properties per class
can be labeled with the Default meta tag (assuming it has arguments). VB.NET
allows you to write directly to this paradigm. For each read/write property,
a method called "get_[PropertyName]" and a method called
"set_[PropertyName]" are created, and tagged as properties. Using the VB
Default keyword tags one of those properties as the default (so the compiler
understands which one you are calling if you don't use the property name,
but rather the array-style invokation). Note that VB allows you to use
either style of invokation for the default (with the name or nameless
array-style - which comes in handy when you can create more than one named
property statement with arguements). For all other (non-default) properties,
you must specify the member name.

In C#, you will always create exactly one Property (the Indexer), which
compiles to one or two underlying methods called exactly "get_Item" and
"set_Item" (depends on if it's read-only or not). You can change the
underlying method name only by using the IndexerName attribute, but I think
that's rather silly. At any rate, you can overload this property with as
many formal argument lists as you want, but you cannot create a seperate
named Property with an arguement list in the same class.

Just seems a little ironic that VB, (usually the more abstract and removed
syntax) in this case actually reads closer to what the underlying IL
produces and gives you the fully-functional deal, while C# is more limited
and demands bizzar syntax on top of it (for no good reason that I can come
up with). In VB, it's pretty straight-forward - all properties can have zero
or more arguments. This is consistant and easy to remember. In C#, only the
Indexer can have properties, and it's written differently from all other
properties.

-Rob Teixeira [MVP]

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"Rob Teixeira [MVP]" <RobTeixeira@@msn.com>> wrote:
Actaully, VB supports Properties with arguments, which is in fact, far more flexible than Indexers - because you can have more than one per class for starters.


You can have more than one indexer per class in C#. You just can't have
more than one indexer with the same parameters signature.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #11
<"Rob Teixeira [MVP]" <RobTeixeira@@msn.com>> wrote:
You can have only one indexer in C#, though it can be overloaded.


Oh, if you want to look at it that way, I agree. I tend to think of
different overloads as different methods/indexers, eg the class

class Test
{
public void Foo()
{
}

public void Foo(int x)
{
}
}

has two methods in my view, rather than one method with two overloads.
I can see the reason for looking at it your way as well.

<snip>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
21
by: b83503104 | last post by:
Hi, Can someone tell me the difference between single quote and double quote? Thanks
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
21
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
12
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
5
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference:...
9
by: viki1967 | last post by:
Hi all! This new forum its great! :) Congratulations !!! My answer: why this my code not working? Nothing error but not work the difference.... : <html>
11
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.