Jump to content
  • Advertisement
Sign in to follow this  
nordwindranger

[.net] passing classes (c#)

This topic is 3882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

----language is C#----- I have run into a situation where I unforunately need two seperate lists that reference the same objects. From what I understand of C#, classes are automatically passed as references so...
class foo()
{
}

class fooCollector()
{
 list<foo> list1 =new list<foo>();

 public void addFoo(foo item)
 {
  list1.add(item);
 }
}

class fooOriginator()
{
 private foo newFoo=new foo();
 list<foo> list2=new list<foo>()

 private void someMethod()
 {
  list2.add(newFoo);
  fooCollectior.addFoo(newFoo)
 }
}
this code would result in both lists having a refence to the same foo object right? Or does it create two seperate foo objects? thanks [Edited by - nordwindranger on February 1, 2008 4:11:21 PM]

Share this post


Link to post
Share on other sites
Advertisement
Yes, they should both refer to the same Foo. You can also check this by calling Object.Equals() which compares object identity if you don't override it to do something different for your derived types.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!