Doubt

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Baskar RajaSekharan

    Doubt

    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


  • Jon Skeet [C# MVP]

    #2
    Re: Doubt

    Baskar RajaSekharan <rbk@srasys.co. in> wrote:[color=blue]
    > 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.[/color]

    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 Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • PVS

      #3
      Re: Doubt

      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

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1a1aa7 7e13ebaa7a989a6 c@msnews.micros oft.com...[color=blue]
      > Baskar RajaSekharan <rbk@srasys.co. in> wrote:[color=green]
      > > 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.[/color]
      >
      > 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 Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Doubt

        PVS <absolutely_raj a@yahoo.com> wrote:[color=blue]
        > Does the "params" modifier allow passing parameters of different datatypes?
        > I think it accepts only single datatype array. If yes, how to pass that?[/color]

        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.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Jeroen Smits

          #5
          Re: Doubt

          "PVS" <absolutely_raj a@yahoo.com> wrote in message
          news:<O8oUXKDqD HA.3732@tk2msft ngp13.phx.gbl>. ..
          [color=blue]
          > Jon,[/color]
          [color=blue]
          > Does the "params" modifier allow passing parameters of different[/color]
          datatypes?
          [color=blue]
          > I think it accepts only single datatype array. If yes, how to pass that?[/color]

          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 ) {

          }

          "PVS" <absolutely_raj a@yahoo.com> wrote in message
          news:<O8oUXKDqD HA.3732@tk2msft ngp13.phx.gbl>. ..
          [color=blue]
          > Jon,[/color]
          [color=blue]
          > Does the "params" modifier allow passing parameters of different[/color]
          datatypes?
          [color=blue]
          > I think it accepts only single datatype array. If yes, how to pass that?[/color]

          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 ) {

          }



          Comment

          Working...