Doubt

  • Thread starter Thread starter Baskar RajaSekharan
  • Start date Start date
B

Baskar RajaSekharan

Hi,

Please let me know whether it's possible in C# .

I want to crate one Method, which will accept any Number of
Parameter and Different DataTypes.

Note: 1. Without Overloading Methods

2. Similarly like Param array in VB.


Regards,
R.Baskar
 
Baskar RajaSekharan said:
Please let me know whether it's possible in C# .

I want to crate one Method, which will accept any Number of
Parameter and Different DataTypes.

Note: 1. Without Overloading Methods

2. Similarly like Param array in VB.

I think the "params" modifier is what you're after here.

See http://www.pobox.com/~skeet/csharp/parameters.html for a brief
explanation, or MSDN for a fuller one.
 
Jon,
Does the "params" modifier allow passing parameters of different datatypes?
I think it accepts only single datatype array. If yes, how to pass that?

Regards,
PVS
 
PVS said:
Does the "params" modifier allow passing parameters of different datatypes?
I think it accepts only single datatype array. If yes, how to pass that?

If you make your parameter of type object[], any type can be passed.
It'll be up to the method to work out what to do with the parameter
though.
 
Does the "params" modifier allow passing parameters of different datatypes?

I think it accepts only single datatype array. If yes, how to pass that?

Define it of the array type object. Because all types inherit from object,
you can pass anything to it.

Something like

void method( params object[] args ) {

}

Does the "params" modifier allow passing parameters of different datatypes?

I think it accepts only single datatype array. If yes, how to pass that?

Define it of the array type object. Because all types inherit from object,
you can pass anything to it.

Something like

void method( params object[] args ) {

}
 
Back
Top