Search Results

Search found 2 results on 1 pages for 'altefquatre'.

Page 1/1 | 1 

  • [C#] How to share a variable between two classes?

    - by Altefquatre
    Hello, How would you share the same object between two other objects? For instance, I'd like something in that flavor: class A { private string foo_; // It could be any other class/struct too (Vector3, Matrix...) public A (string shared) { this.foo_ = shared; } public void Bar() { this.foo_ = "changed"; } } ... // inside main string str = "test"; A a = new A(str); Console.WriteLine(str); // "test" a.Bar(); Console.WriteLine(str); // I get "test" instead of "changed"... :( I read there is some ref/out stuff, but I couldn't get what I'm asking here. I could only apply some changes in the methods scope where I was using ref/out arguments... I also read we could use pointers, but is there no other way to do it? Thanks Altefquatre

    Read the article

  • How to share a variable between two classes?

    - by Altefquatre
    How would you share the same object between two other objects? For instance, I'd like something in that flavor: class A { private string foo_; // It could be any other class/struct too (Vector3, Matrix...) public A (string shared) { this.foo_ = shared; } public void Bar() { this.foo_ = "changed"; } } ... // inside main string str = "test"; A a = new A(str); Console.WriteLine(str); // "test" a.Bar(); Console.WriteLine(str); // I get "test" instead of "changed"... :( I read there is some ref/out stuff, but I couldn't get what I'm asking here. I could only apply some changes in the methods scope where I was using ref/out arguments... I also read we could use pointers, but is there no other way to do it?

    Read the article

1