Newbie asks: How does one implement this pattern in C#?

  • Thread starter Thread starter Gomaw Beoyr
  • Start date Start date
Have you investigated nullable types in 2.0 yet?

Yes, you can use nullable types, but it then becomes really ugly
(I simplify here to one in and two out):

void F(double x, ref double? a, ref double? b) {
if (a != null) ...
if (b != null) ...
}

A caller that needs a but not b would have to do like this:

double? a;
double? b;
...
a = 0.0; // To make sure it's not null!
F(x, ref a, ref b);

And that sucks big time.

/Gomaw
 
Gomaw Beoyr said:
I thank you for your efforts, but all I wanted to know was if
there is any standard way in C# to do what you do in C when you
send the adderss of (i.e. pointer) to an out-variable as NULL,
to indicate that the value isn't needed by the caller.

I think what people have been trying to get you to do is to think about
the larger problem. It's really not a good idea to try to apply idioms
from one language or platform to another. Some of the worst Java code
I've seen is by C++ programmers trying to treat Java as if it were C++,
for instance. In this case, you're trying to write C# as if it were C.
It's not. You need different idioms - try to *think* in C# instead of
thinking in C and then translating those thoughts into C#.
 

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