Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Function Parameters...

Function Parameters...

Scheduled Pinned Locked Moved C#
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prashant C
    wrote on last edited by
    #1

    How to define optional parameter in C# fuction or can define single optional parameter???? please help me Thanks in Advance..

    T P S 3 Replies Last reply
    0
    • P Prashant C

      How to define optional parameter in C# fuction or can define single optional parameter???? please help me Thanks in Advance..

      T Offline
      T Offline
      theScorp
      wrote on last edited by
      #2

      C# does not support Optional parameters.. Need to pass NULL instead.

      "If our Mind can, the Program can !!"

      1 Reply Last reply
      0
      • P Prashant C

        How to define optional parameter in C# fuction or can define single optional parameter???? please help me Thanks in Advance..

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Do you mean how can you add a variable number of parameters?

        public void DoSomething(params object[] parameters)
        {
          foreach (object parameter in parameters)
          {
            ...
          } 
        }
        

        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • P Prashant C

          How to define optional parameter in C# fuction or can define single optional parameter???? please help me Thanks in Advance..

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          Create an overload. As long as the function signatures differ in the parameter list (or return type, but not advisable), you can have two functions with the same name. You end up with something like this:

          function Add(object item)
          {
          ...
          }

          function Add(object item, string name)
          {
          ...
          }

          ----------------------------- In just two days, tomorrow will be yesterday.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups