Resetting all object variables in c#

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

    #1

    Resetting all object variables in c#

    I wont to reset all the variables in a c# object at run time, I was hoping
    for a field collection or some similar method of iterating through the
    variables.

    Any ideas ???

    --
    Lee.
  • Jon Skeet [C# MVP]

    #2
    Re: Resetting all object variables in c#

    lee <lee@discussion s.microsoft.com > wrote:[color=blue]
    > I wont to reset all the variables in a c# object at run time, I was hoping
    > for a field collection or some similar method of iterating through the
    > variables.
    >
    > Any ideas ???[/color]

    Well, you could use reflection. It won't be terribly fast 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

    • Dennis Myrén

      #3
      Re: Resetting all object variables in c#

      Why not having a Reset something method on that object, doing it for you.

      --
      Regards,
      Dennis JD Myrén
      Oslo Kodebureau
      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1c053f 2283a405798b8f6 @msnews.microso ft.com...[color=blue]
      > lee <lee@discussion s.microsoft.com > wrote:[color=green]
      >> I wont to reset all the variables in a c# object at run time, I was
      >> hoping
      >> for a field collection or some similar method of iterating through the
      >> variables.
      >>
      >> Any ideas ???[/color]
      >
      > Well, you could use reflection. It won't be terribly fast though...
      >
      > --
      > 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: Resetting all object variables in c#

        Dennis Myrén <dennis@oslokb. no> wrote:[color=blue]
        > Why not having a Reset something method on that object, doing it for you.[/color]

        Yes, that's certainly the better bet if you are in control of the type.
        Of course it means you've got to modify the method every time you add a
        field, too. I was assuming that the OP didn't want to do that for
        whatever reason, but I think they'd have to be pretty good reasons :)

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

        • Patrice

          #5
          Re: Resetting all object variables in c#

          Or also just creating a new instance...

          Patrice

          --

          "Dennis Myrén" <dennis@oslokb. no> a écrit dans le message de
          news:ZoGmd.1715 5$Km6.199541@ne ws4.e.nsc.no...[color=blue]
          > Why not having a Reset something method on that object, doing it for you.
          >
          > --
          > Regards,
          > Dennis JD Myrén
          > Oslo Kodebureau
          > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          > news:MPG.1c053f 2283a405798b8f6 @msnews.microso ft.com...[color=green]
          > > lee <lee@discussion s.microsoft.com > wrote:[color=darkred]
          > >> I wont to reset all the variables in a c# object at run time, I was
          > >> hoping
          > >> for a field collection or some similar method of iterating through the
          > >> variables.
          > >>
          > >> Any ideas ???[/color]
          > >
          > > Well, you could use reflection. It won't be terribly fast though...
          > >
          > > --
          > > Jon Skeet - <skeet@pobox.co m>
          > > http://www.pobox.com/~skeet
          > > If replying to the group, please do not mail me too[/color]
          >
          >[/color]


          Comment

          Working...