Translate C# to VB.NET

D

dwm

Not sure where to post this question - C# or VB.NET - so I'm posting here.

Should be simple for those familiar with C#.

in C#:

xs = new XmlSerializer(typeof(LogStrResponse));

What is the equivalent statement in vb.net?

More specifically, I'm not sure how to replace the 'typeof' function call.

Thanks in advance
 
C

Chris Dunaway

Not sure where to post this question - C# or VB.NET - so I'm posting here.

Should be simple for those familiar with C#.

in C#:

xs = new XmlSerializer(typeof(LogStrResponse));

What is the equivalent statement in vb.net?

More specifically, I'm not sure how to replace the 'typeof' function call.

Thanks in advance

Do yourself a favor and learn C#. It's not any more difficult than VB
and once you get past the syntax, it's virtually the same. Even if
you prefer to code in VB.Net, having C# in your back pocket will help
you in the long run. And, you won't have to ask how to translate code
any more!

Chris
 
C

Cor Ligthert[MVP]

Chris,

An advice that looks to me as telling to somebody who speaks fluently
English to learn Chinese.

Even if you prefer to talk in English, having Ch in your back pocket will
help
you in the long run. And, you won't have to ask how to translate the
Chinese menu
any more!


Cor
 
M

Michael C

Cor Ligthert said:
Chris,

An advice that looks to me as telling to somebody who speaks fluently
English to learn Chinese.

Actually that makes sense if it takes a few days to switch from English to
Chinese and you live in a country where most people speak chinese. If it was
that easy why would you continue speaking English?

Michael
 
C

Cor Ligthert[MVP]

An advice that looks to me as telling to somebody who speaks fluently
Actually that makes sense if it takes a few days to switch from English to
Chinese and you live in a country where most people speak chinese. If it
was that easy why would you continue speaking English?
But it does not take a few days, moreover, it does not take a few days to
learn C#.

However, I often get the idea that persons who make programs in C# thinks
that everything is 1:1 the same in VB with the exception that the keywords
are different. Those are often telling here all kind of things which are
perfectly valid for C# but not for VB, because in some cases the languages
are a little in theire syntactical use while that use is not always
efficient as it can be.

The same exist in natural languages by the way where for some things are in
many languages less words then in the other.

(By instance words as null, nothing and zero in English can give in
programming give much misunderstanding because those have not always an
equivalent in other languages then English)

Cor
 
M

Michael C

Cor Ligthert said:
But it does not take a few days, moreover, it does not take a few days to
learn C#.

Not to learn C# but to *switch* from VB. Perhaps you think C# is more
different from VB than it is.
However, I often get the idea that persons who make programs in C# thinks
that everything is 1:1 the same in VB with the exception that the keywords
are different.

Not 1:1 but pretty close.
Those are often telling here all kind of things which are perfectly valid
for C# but not for VB, because in some cases the languages are a little in
theire syntactical use while that use is not always efficient as it can
be.

There's really not a lot that C# can do that VB can't.
The same exist in natural languages by the way where for some things are
in many languages less words then in the other.

Of course a real language is much harder to learn.
(By instance words as null, nothing and zero in English can give in
programming give much misunderstanding because those have not always an
equivalent in other languages then English)

Naturally there's a few minor differences that you will need to learn. For
example comparing null strings to an empty string will give false in C# but
true in VB I believe. These things aren't that difficult to learn.

Michael
 
C

Cor Ligthert[MVP]

Michael,

For Dutch people is speaking (not writing) German or English very easy. They
don't understand why German or people from English speaking countries don't
speak Dutch when they are as guest in our country. Speaking those languages
is so simple, it is almost Dutch.

In my idea are you doing this the same with VB and C#, often contributions
from you in this newsgroup shows this.

I write very intensively in C# and when I have done that, I have to
considerate at VB that C# is not VB (and vice vers).

Cor
 
M

Michael C

Cor Ligthert said:
Michael,

For Dutch people is speaking (not writing) German or English very easy.
They don't understand why German or people from English speaking countries
don't speak Dutch when they are as guest in our country. Speaking those
languages is so simple, it is almost Dutch.

In my idea are you doing this the same with VB and C#, often contributions
from you in this newsgroup shows this.

On occasion I have forgotten to reply using VB. No big deal.
I write very intensively in C# and when I have done that, I have to
considerate at VB that C# is not VB (and vice vers).

What you said before about VB and C# being almost 1:1 with keyword changes,
I think that is fairly accurate.
 
M

Michael C

Michael D. Ober said:
There are also some syntactic changes. The one I run into most is that in
C# Winform event handlers are wired up in the designer code where it is
harder to get to. In VB these same event handlers are wired up in code
that you have direct access to.

That is correct but these changes are pretty minor, easy to learn and
handled by the designer anyway.
 
T

Tom Shelton

I was merely pointing out a difference between the languages. Personally I
prefer VB's method because it's consistent with other objects that expose
events. But as you said, once you realize where the wiring is occurring,
it's not a real issue.

Mike.
 
M

Michael C

Michael D. Ober said:
I was merely pointing out a difference between the languages. Personally
I prefer VB's method because it's consistent with other objects that
expose events. But as you said, once you realize where the wiring is
occurring, it's not a real issue.

I don't mind the Handles keyword but isn't vb less consistant seeing it has
the Handles keyword and AddHandler keyword when c# just has +=?

Michael
 
H

Herfried K. Wagner [MVP]

Michael C said:
I don't mind the Handles keyword but isn't vb less consistant seeing it
has the Handles keyword and AddHandler keyword when c# just has +=?

Not really. C# simply does not support declarative event handling, so '+='
is not equivalent to 'WithEvents'/Handles' *and* 'AddHandler'.
 
M

Michael C

Herfried K. Wagner said:
Not really. C# simply does not support declarative event handling, so
'+=' is not equivalent to 'WithEvents'/Handles' *and* 'AddHandler'.

How is it different? Surely all 3 of those just call whatever += calls.

Michael
 
H

Herfried K. Wagner [MVP]

Michael C said:
How is it different? Surely all 3 of those just call whatever += calls.

'WithEvents'/'Handles' are declarative, whereas '+='/'AddHandler' are
imperative.
 

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

Top