rusoaica's Profile User Rating: *****

Reputation: 209 Stalwart
Group:
Authors
Active Posts:
674 (0.66 per day)
Joined:
10-March 12
Profile Views:
6,485
Last Active:
User is offline Dec 23 2014 04:35 AM
Currently:
Offline

Previous Fields

Country:
RO
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
250

Latest Visitors

Icon   rusoaica I'd love to change the World, but they won't give me the Source Code

Posts I've Made

  1. In Topic: passing an object as a parameter creates a copy of it, how to avoid it

    Posted 17 Dec 2014

    i'm glad i could help :)
  2. In Topic: passing an object as a parameter creates a copy of it, how to avoid it

    Posted 17 Dec 2014

    i see two options here:
    you either use a method with a reference object parameter, and you apply the action on both objects, like this:
    static void StopPlayer(ref MyPlayer player)
    {
        player.Stop();
    }
    
    static void Main()
    {
        MyPlayer OriginalPlayer = new MyPlayer();
        StopPlayer(ref OriginalPlayer);   
    }
    
    

    or, you make the player a class-level field and apply the actions in a non-parameters method directly on the original variable. Like so:
    MyPlayer OriginalPlayer = new MyPlayer();
    
    static void StopPlayer()
    {
        OriginalPlayer.Stop();
    }
    
    static void Main()
    {
        StopPlayer(); 
    }
    
    
  3. In Topic: passing an object as a parameter creates a copy of it, how to avoid it

    Posted 17 Dec 2014

    when you pass a parameter by value, whatever changes you make to that parameter are not reflected on the original parameter (but over an instance, a copy of it). On the other hand, when you pass a parameter by reference, any action you apply on that parameter is reflected on the original parameter. So, for example:

    static void Method(ref int i)
    {
        i = i + 44;
    }
    
    static void Main()
    {
        int val = 1;
        Method(ref val);
        Console.WriteLine(val);
        // Output: 45
    }
    
    


    So, the initial integer "val" has a value of 1. After we pass it to a method by reference, the method is not only changing the local parameter ("i" in our case), but also the calling integer "val". So, after passing it by reference, it's value won't be 1 anymore, but 45, because modifying the reference parameter value it also means modifying the original variable. In your case, i assume that this would translate like this: if you pass the player as a value object, whatever action you apply on it will only be reflected on the local player, the value one (a copy of the original player). When you pass the player object by reference, whatever action you apply on the reference object will ALSO be reflected in the original player object.
    I hope this helps.

    There is no way to not create another object when you call a method with that object as parameter. That's the whole point of adding parameters to the method. In your case, you can simply ignore the local player objects and use them as means to modify the original player objects.
  4. In Topic: passing an object as a parameter creates a copy of it, how to avoid it

    Posted 17 Dec 2014

    i'm not sure if this is the answer, but this might help you.
  5. In Topic: Is flash still worth attention?

    Posted 16 Dec 2014

    Yes, I do. You can still develop in flash, no one is stopping you from doing so, but keep in mind that it will end someday. And the sooner you evolve, the better. Instead of learning it when flash would have been far gone, you would be mastering it by that time, if you start learning it now.
    As a matter of fact, i kinda am in your shoes. The only difference is that i'm not switching to HTML5, i'm switching to XAML/WPF, because they offer the alternative for flash when it comes to desktop software. And they also replace the old WinForms, which are around since the 80's. This means evolution: why continue learning/using an old technology that is no longer supported/upgraded/etc, when i can simply leave the dinosaur-age behind and switch to the new age? ;)

My Information

Member Title:
They're watching you, Neo!
Age:
30 years old
Birthday:
August 22, 1984
Gender:
Location:
Bucharest, Romania
Interests:
Music, Astronomy, Programming, Artificial Intelligence, Electronics, SF, pencil drawing and gothic.
Full Name:
Юлия Данилова (Yulia Danilova)
Years Programming:
5
Programming Languages:
C, C++, C#, VB.NET

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://www.rusoaica.com
Yahoo:
Yahoo  rusoaica3@yahoo.com
Facebook:
https://www.facebook.com/yulia.danilova.587

Comments

Page 1 of 1
  1. Photo

    rusoaica Icon

    19 Oct 2014 - 04:35
    Binars: you're welcome!
  2. Photo

    binars Icon

    19 Oct 2014 - 04:11
    Thank you for the nice welcome!
  3. Photo

    rusoaica Icon

    16 Oct 2014 - 12:20
    thanks... i'm a big fan of Star Trek and LCARS ;)
  4. Photo

    dyo Icon

    16 Oct 2014 - 12:16
    Nice website :-)
Page 1 of 1