✅ Comparing properties of a values of lists
i have 2 lists
List<Animal>
and List<Dog>
and both Animal
and Dog
have the property id
i'm trying to insert a list of Dog
into the list of Animal
but i don't want to insert Animals with duplicate id
's51 Replies
paste this question into chatgpt. and i think u will be happy with your answer
also bonus: ask it to explain
can you think of a way to calculate
dogsNotInAnimals
?i mean might there be a performance issue if
List<Animal>
is quite bigsure, but then you shouldn't be having a list in the first place
but then i won't be improving my explanation skills😔
don't do that lmao
Now i wonder eiter my skills are bad or i got something else from it than you?
wat
wat
wat
Ask chatgpt for an explaination and solution
If you're gonna tell someone to just go ask a text prediction engine then why even respond in the first place? This person asked a question, you gave them a non-answer
If they wanted to use chatgpt then they would've done that
Ah then i understand
they asked a question here
I think its a tool that is often not looked at, so
it's looked at too much lmao
i know how to do it
however
Don't.
i was asking if there is a better way than looping
Plenty
gimme
Assuming we can change some types around
if you are working with two lists, there isnt much we can do
Can you think of a collection type that could be used to help with the "unique id" requirement?
wat
what part of that question made you go wat?
wat
so I know what to explain
collection type?
List<T>
is a collection type
T[]
(array) is also a collection type
can you name some more?why T?
its just a placeholder for the actual type
oh
by convention we use the letter T for that
hashmap
Yep!
dictionary
yep!
called
HashSet
in C#, but its the sameoh yes
so what do hashsets and dictionaries have as their "special" property?
no duplicate?
thats hashsets, yes
dictionaries are keyed
meaning you set a key for each value, and you can only have one item per key
do one of these sound good for storing a list of items with unique IDs?
so you can set id as the key for dictionaries?
that sounds like an excellent idea
but i still have to loop to convert from list to dictionary
for one, it makes it
O(1)
to look if an ID already existsoh wait i don't know if i can
instead of
O(N)
since i'm using a winform datasource
okay
You're a beginner, right?
sorta yes
Don't think you need to worry about performance of filtered list inserts etc just yet 🙂
i tried using a directory / bindingsource
but it doesn't update correctly
how should i do it?
this gives me only one value?
dead chat