Special Assignement

Hi guys, I have there variables setup like this, I would like in one line be able to assign OldID to ID and "1111" to OldID, is it possible

ID = null

OldID="0000"

ID = OldID = "1111";

final result would be:

ID = "0000"

OldID = "1111"



Answer this question

Special Assignement

  • ljkyser

    for no a particular reason, I was under the impression that under C# you can do that. Curiosity that's all. thank y'all


  • cbpd86

    The line:

    ID = OldID = "1111";

    will assign "1111" to both ID and OldID (as you have probably discovered). There is no way to do what you want in a single line.

    May I ask why you're looking for a single-line solution to this

    -Tom Meschter
    Software Dev, Visual C# IDE



  • sobo1

    There is no language construct that would allow you to do this in one line. You could easily write a helper method to accomplish this, though. Are you expecting this operation to be atomic (i.e. Multiple threads can call the helper method and you won't lose or duplicate IDs.) If so, you would need to use synchronization primitives like Monitor (aka C# lock) to ensure that it is thread-safe.


  • Special Assignement