Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by I_Love_Misato · Sep 15, 2014 at 09:31 AM · c#linqquery

Grouping objects by a reference type field

Hello, everybody! I have a class that contains a hashset, like this:

 class A : MonoBehavior{
       public HashSet<SomeClass> hs;
 }

And I need group the objects of the class A by the contents of their hs. I can do something like this:

 List<A> SomeList;
 var query = 
       from a in SomeList
       group a by a.hs;

but it won't work since the HashSet is a reference type. If I make any function that compares this collection elementwise, how should I implement it in the linq-query?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VesuvianPrime · Sep 15, 2014 at 12:12 PM 0
Share

Hey $$anonymous$$pyTou

I suspect you're going to need to use a lambda in your query to generate some kind of hash based on the contents of the collection.

In general you should try to avoid using Linq in Unity like the plague. I've just had to refactor a ton of code after learning that Linq and IEnumerables in $$anonymous$$ono leak memory all over the place.

avatar image I_Love_Misato · Sep 15, 2014 at 03:10 PM 0
Share

Could you show some example of using lambda in this query in my context? Unfortunately, I would hardly refuse such a powerfull instrument as Linq and make so many things manually, I'm too lazy for this.

avatar image Landern · Sep 15, 2014 at 03:40 PM 0
Share

@VesuvianPrime do you have a source for the memory leak?

@$$anonymous$$pyTou, regardless if you use a query expression(what you did above) or a $$anonymous$$ethod Expression(the lambda and what a query expression is compiled/transformed to) you will be doing the same thing, but displaying it in code differently.

Query Syntax and $$anonymous$$ethod Syntax in LINQ (C#) Linq Query Expressions

avatar image I_Love_Misato · Sep 15, 2014 at 03:59 PM 0
Share

Landern, sorry, but there is no any useful information for me, there is just a basics of linq. $$anonymous$$aybe, an easy solution for my question doesn't exist.

avatar image VesuvianPrime · Sep 15, 2014 at 04:01 PM 0
Share

http://www.gamasutra.com/blogs/WendelinReich/20131109/203841/C_$$anonymous$$emory_$$anonymous$$anagement_for_Unity_Developers_part_1_of_3.php

http://www.gamasutra.com/blogs/WendelinReich/20131119/203842/C_$$anonymous$$emory_$$anonymous$$anagement_for_Unity_Developers_part_2_of_3.php

http://www.gamasutra.com/blogs/WendelinReich/20131127/203843/C_$$anonymous$$emory_$$anonymous$$anagement_for_Unity_Developers_part_3_of_3.php

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Confusion over LINQ syntax 2 Answers

[Solved] How to LINQ to ArrayList all the Transform within a Range? 1 Answer

Custom pathfinding and node-values 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges