C
C#4w ago
merlo17

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
No description
No description
No description
28 Replies
merlo17
merlo17OP4w ago
Forgot to include the UserDataManager part of UserData.cs
No description
mg
mg4w ago
OwnedAircraft has ATK, but Dictionary<TKey, TValue> does not ActiveAircraft is a dictionary, not an aircraft @merlo17
merlo17
merlo17OP4w ago
okay, so if I change ActiveAircraft to a string, how do I make it search the dictionary for an OwnedAircraft with the same name?
mg
mg4w ago
should ActiveAircraft be a string? what's it supposed to represent?
merlo17
merlo17OP4w ago
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
mg
mg4w ago
so it represents an aircraft, what should the type be then?
merlo17
merlo17OP4w ago
String I believe
mg
mg4w ago
is a string an aircraft? you've written an OwnedAircraft class
merlo17
merlo17OP4w ago
It'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
mg
mg4w ago
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
merlo17
merlo17OP4w ago
That's what I was thinking of doing So is it that I need a new class for ActiveAircraft?
mg
mg4w ago
you don't need a new class you just need to change ActiveAircraft's type to OwnedAircraft
merlo17
merlo17OP4w ago
so change Dictionary to OwnedAircraft?
mg
mg4w ago
yep
merlo17
merlo17OP4w ago
No description
merlo17
merlo17OP4w ago
No description
merlo17
merlo17OP4w ago
It did solve the CS1061 though
mg
mg4w ago
Do you know what those angled brackets and type names mean?
merlo17
merlo17OP4w ago
Roughly Let me guess I need to get rid of them?
mg
mg4w ago
yes your OwnedAircraft class isn't generic
merlo17
merlo17OP4w ago
I cannot say how many times coding has made me feel dumb
mg
mg4w ago
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.
merlo17
merlo17OP4w ago
Thank you
mg
mg4w ago
part of the learning process
merlo17
merlo17OP4w ago
yep
mg
mg4w ago
when you find yourself roughly knowing something, take it as a direction to sharpen your understanding of it
merlo17
merlo17OP4w ago
Will do. Thank you again
mg
mg4w ago
sure thing

Did you find this page helpful?