Fast search an object in a list using his attribute
So I have a list of ships and each ship has a length width, mass and a name. We need to write a method that searches in this list the oobject using his name attribute. So only a string is given with the method. for example public Ship SearchShip(string shipName){}
3 Replies
We can not use lambdas, cuz we only learn it later in our course.
iterate over the
ships
and compare the Naam
with the shipName
(unhide to see an example of an solution)Is the use of a dictionary not faster? and using the name of the object as a key