Re: C# Vs VB.NET
- From: "Philipp Schumann" <phil@xxxxxxxxx>
- Date: Thu, 31 Mar 2005 19:23:47 +0100
> If you're opening streams in VB.NET and not calling Dispose or Close in
Or almost any other IDisposable, for that matter.
> a finally block, you've got a potential resource leak.
I presume it is precisely for all the VB developers out there that most
IDisposables in the framework go the extra length and make sure everything
is disposed of properly in the finalizer =) that doesn't necessarily mean
that all IDisposables also do that.
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> schrieb im Newsbeitrag
news:MPG.1cb63d5ace47dc1b98bf0e@xxxxxxxxxxxxxxxxxxxxxxx
> Lucvdv <replace_name@xxxxxxxx> wrote:
>> > <"=?Utf-8?B?U2FyYXRoIEJhYnU=?=" <Sarath
>> > Babu@xxxxxxxxxxxxxxxxxxxxxxxxx>> wrote:
>> > > Can anyone let me know why most companies prefer C# when the same
>> > > task can
>> > > be accomplished using VB.NET in a simpler and easier way..?
>> >
>> > Perhaps because your idea of simpler and easier isn't theirs?
>>
>> The question is who is wrong.
>>
>> Neither and both, IMO: C# will be easier for C/C++ and Java developers,
>> VB.Net will be preferred by those who were used to VB6.
>>
>> VB requires some more typing, but I find that makes the result more
>> readable. I've seen C/C++/C# code where almost every } is followed by a
>> comment to indicate what statement it belongs to, VB is self-documenting
>> in
>> that regard.
>
>
> Just because you've seen some bad C# code doesn't mean it *has* to be
> worse :)
>
> (I've seen some really horribly written VB.NET code, but that doesn't
> mean it all is.)
>
>> In the DirectX SDK you find sample code for VB and C# that only differs
>> in
>> syntax, where program structure and even comment text are fully identical
>> because it was written in one language and then simply syntax-translated
>> to
>> the other. Translation can usually be done line by line, keyword by
>> keyword (the most work is C# to VB, finding the right } and replacing it
>> by
>> the right keyword each time).
>
> Sure.
>
>> > Personally I find C# simpler, partly because as a language it's so much
>> > smaller, without all the legacy functions that VB.NET carries around
>> > with it.
>>
>> Legacy functions are an extension you don't have to use.
>> Just leave Microsoft.Visualbasic.Compatibility out.
>
> They're part of the language though, aren't they? That means there are
> more keywords which you have to avoid, unless I'm missing something.
>
>> > I suspect if I used VB.NET regularly, the thing I'd miss most from C#
>> > is the "using" statement - it's so much easier to write
>> >
>> > using (Stream s = ...)
>> > {
>> > ...
>> > }
>> >
>> > than manually putting the try/finally in the right place.
>>
>> I don't see the relation to exception handling, or else I missed
>> something
>> in C# (I haven't used it much).
>>
>> The VB equivalent is
>> With s As Stream = ...
>> ...
>> End With
>> Different syntax, exact same thing (AFAIK).
>
> No, far from the same thing. The using statement is equivalent to:
>
> Stream temp = null;
> try
> {
> // instantiate stream or whatever
> temp = ...;
> // do stuff
> }
> finally
> {
> if (temp != null)
> {
> temp.Dispose();
> }
> }
>
> If you're opening streams in VB.NET and not calling Dispose or Close in
> a finally block, you've got a potential resource leak.
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
.
- References:
- C# Vs VB.NET
- From: Sarath Babu
- Re: C# Vs VB.NET
- From: Jon Skeet [C# MVP]
- Re: C# Vs VB.NET
- From: Lucvdv
- Re: C# Vs VB.NET
- From: Jon Skeet [C# MVP]
- C# Vs VB.NET
- Prev by Date: Re: C# Vs VB.NET
- Next by Date: Re: C# Vs VB.NET
- Previous by thread: Re: C# Vs VB.NET
- Next by thread: Re: C# Vs VB.NET
- Index(es):
Relevant Pages
|