Need help with a CS1061 Error that is making no sense
The exact error is this:
CS1061: 'Dictionary<string, OwnedAircraft>' does not contain a definition for 'ATK' and no accessible extension method 'ATK' accepting a first argument of 'Dictionary<string, OwnedAircraft>' could be found (are you missing a using directive or assembly reference?)
However the Dictionary does have a definition for 'ATK'. And when I follow the code back through all the references, it is calling to the dictionary correctly. So I don't know what's wrong.
The first two screenshots are in EventHandler.cs, the third in UserData.cs


28 Replies
Forgot to include the UserDataManager part of UserData.cs

OwnedAircraft
has ATK
, but Dictionary<TKey, TValue>
does not
ActiveAircraft
is a dictionary, not an aircraft
@merlo17okay, so if I change ActiveAircraft to a string, how do I make it search the dictionary for an OwnedAircraft with the same name?
should
ActiveAircraft
be a string?
what's it supposed to represent?ActiveAircraft is supposed to be a setting. The user can set an ActiveAircraft from their OwnedAircraft. So that when they use a command, the program uses the aircraft set as ActiveAircraft
so it represents an aircraft, what should the type be then?
String I believe
is a string an aircraft?
you've written an
OwnedAircraft
classIt's supposed to hold the name of the Aircraft set as ActiveAircraft so that the program can search the user's Dictionary of OwnedAircraft for the one with that same name and then pull the stats for that aircraft. However that wasn't working too well because I couldn't figure out how to make it search for that. So then I decided to set it as another Dictionary with the same name and when the user sets their active aircraft, it just writes all the respective values in.
Though I haven't yet implemented the command to set an ActiveAircraft, and now I realise my plan wouldn't have worked as I'd encounter the same issue I am now
but why store a string that you use to search for an aircraft when you can just store the aircraft?
instead, the user can set their active aircraft by name, and the search is done when they set it, and then when it's used, you don't have to search
That's what I was thinking of doing
So is it that I need a new class for ActiveAircraft?
you don't need a new class
you just need to change
ActiveAircraft
's type to OwnedAircraft
so change Dictionary to OwnedAircraft?
yep


It did solve the CS1061 though
Do you know what those angled brackets and type names mean?
Roughly
Let me guess
I need to get rid of them?
yes
your
OwnedAircraft
class isn't genericI cannot say how many times coding has made me feel dumb
Generic classes and methods - C#
Learn about generics. Generic types maximize code reuse, type safety, and performance, and are commonly used to create collection classes.
Thank you
part of the learning process
yep
when you find yourself roughly knowing something, take it as a direction to sharpen your understanding of it
Will do. Thank you again
sure thing