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. using params problem

using params problem

Scheduled Pinned Locked Moved C#
questionhelptutorial
3 Posts 2 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.
  • I Offline
    I Offline
    impeham
    wrote on last edited by
    #1

    i have 2 functions: void Log(LogTypes type, string message, string context); void Log(LogTypes type, string message, params object[] parameters); when i use the following call: Logger.Log(LogTypes.Message, "{0} test", "ddd"); // the "{0}" will be // replaced by "ddd" in format message i get to a problem - how can i force the usage of either one of the functions in the call (for example - one time i want "ddd" to be a context and in another - be a parameter) Any ideas? Thanks.

    J 1 Reply Last reply
    0
    • I impeham

      i have 2 functions: void Log(LogTypes type, string message, string context); void Log(LogTypes type, string message, params object[] parameters); when i use the following call: Logger.Log(LogTypes.Message, "{0} test", "ddd"); // the "{0}" will be // replaced by "ddd" in format message i get to a problem - how can i force the usage of either one of the functions in the call (for example - one time i want "ddd" to be a context and in another - be a parameter) Any ideas? Thanks.

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      The easiest way I can think of is make Context a class called "LogContext". It could be as simple as a wrapper around a string, but at least it differentiates it from a string parameter used in the params argument. One other point, in the naming of your enum. Enums should be singular tense, unless it can be used in a bitmasked way (ie/ are marked with the FlagsAttribute). so for example, LogType.Message <-- singlular as you can only use one at a time UserGroups.User | UserGroups.Administrator <-- example of bitmasked enums

      --- How to get answers to your questions[^]

      I 1 Reply Last reply
      0
      • J J4amieC

        The easiest way I can think of is make Context a class called "LogContext". It could be as simple as a wrapper around a string, but at least it differentiates it from a string parameter used in the params argument. One other point, in the naming of your enum. Enums should be singular tense, unless it can be used in a bitmasked way (ie/ are marked with the FlagsAttribute). so for example, LogType.Message <-- singlular as you can only use one at a time UserGroups.User | UserGroups.Administrator <-- example of bitmasked enums

        --- How to get answers to your questions[^]

        I Offline
        I Offline
        impeham
        wrote on last edited by
        #3

        Thanks. this would probably be the best solution.

        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