can I call from one constructor another constructor ?

  • Thread starter Thread starter Paul
  • Start date Start date
As I start to dig into C#, this is one major issue that I have run into
also. According to the specs for C#, optional parameters are not
supported.



Stano said:
I know that this might be getting away from the original post, but I have
a question about optional paramters in C#.

I originally developed a COM DLL using VB.NET which had an optional
parameter in one of the methods. I ported the entire project to C# (as I
decided C# was the way to go) but I was unable to work out how to redefine
the COM interface in C# with an optional COM parameter.

In the end the COM interface was defined in VB.NET and the rest of the
project was written using C#. I know that this isn't a big deal, but it's
been bugging me for a while now. Does anyone have any ideas on how to do
this?

Thanks.
 
why not try not making them optional?

use overloaded constructors for all scenarios.

example vb:

public function DoSomething(x as string, y as string, z as optional string)
as string

converted to c#

public string DoSomething(string x, string y)
public string DoSomething(string x, string y, string z)

my vb syntax may not be completely correct but hopefully you get the point i
am trying to make
 
It's a distant memory as this was some time ago, but I tried that, and as far as I am aware it didn't work as I was trying to keep the interface binary compatible with my previous definition in VB.NET, so that my clients could install the new version without having to change their code.

Anyway it's a distant memory now as all of my recent development has left the COM world behind, and should I develop any COM interfaces in the future I'll make sure that I keep away from Optional parameters. They're the devil's work ;)

Thanks.
 
Sure you can do this, however it would not be the same COM signature as
the VB.NET code. If the OP is trying to maintain COM interface
compatibility, then this is not viable.

HTH

David
 
Good Point, I didn't thing about breaking interfaces. I guess this is one
of those times where the small differences in the two languages will cause a
problem.
--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
Stano said:
It's a distant memory as this was some time ago, but I tried that, and as
far as I am aware it didn't work as I was trying to keep the interface
binary compatible with my previous definition in VB.NET, so that my clients
could install the new version without having to change their code.
Anyway it's a distant memory now as all of my recent development has left
the COM world behind, and should I develop any COM interfaces in the future
I'll make sure that I keep away from Optional parameters. They're the
devil's work ;)
 
Back
Top