conversion help?

  • Thread starter Thread starter jamie
  • Start date Start date
J

jamie

Yello,
I am having a hard time converting
from vb to cs. I think that vb as
doing a little more behind the scenes,
than I relized...

The prob code:
vb---------------------------------
someMethod(nothing, 0,....,nothing)
-----------------------------------

cs---------------------------------
someMethod(null,0,...., null); //this does not work!!!
-----------------------------------

Seams easy enough, right?... but replacing
that "nothing" with "null" doesn't work due to
the argument being of a reference type.

Does that mean I would have to define, and
initiaize the arguments? I know if I redefine
the function in cs to use an "out" instead of
a "ref" var, that I would not have to initialize
the referenced variable.... but doesnt that mean
I would still have to define a variable?

Any suggestions as to the fastest and cleanest
way of getting the proper syntext for cs would be
greatly appreciated.
(example??)

thanks jamie
..
 
Why exactly doesn't it work? What message are you getting? Is the error at
compile or runtime? Can we wee a little more of the code, enough to be able
to replicate the problem ourselves, thanks.

All that said, there is nothing wrong with passing a null in to a parameter
expecting a reference type. Be default the reference type is passed in by
value. Using the ref keyword merely means that the reference to the
reference type can be modified. Using the out keyword means the parameter
must be initialized by the method.

Have a look at http://www.yoda.arachsys.com/csharp/parameters.html for more
detail.
 
Arguments passed to "ref" parameters must be variables in C#. VB actually
does this behind th scenes to hide this from you.

Similarly for "out" parameters - the arguments must be passed as variables.

BTW: "ref" is unrelated to "reference type". Either reference types or value
types can be passed "ref" or not.

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
 
Back
Top