C
C#2y ago
Ted Bunny

Abstract List of KeyValuePairs

public abstract List<KeyValuePair<string, int>> inventory;
public abstract List<KeyValuePair<string, int>> inventory;
It says I can't do this with a field, and to try a property instead. Doing that doesn't resolve it. I've never received this message when declaring an abstract variable. Any suggestions?
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ted Bunny
Ted Bunny2y ago
Ah ok, I forgot the {get;} Adding that does what I needed. Thanks!
jcotton42
jcotton422y ago
abstract is "this member needs to be implemented by deriving classes" Fields don't have implementations, they just exist Also, why a List of KVP instead of a dictionary?
Ted Bunny
Ted Bunny2y ago
I need non-unique keys
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ted Bunny
Ted Bunny2y ago
I used the auto-suggested version, I forget what it looked like Is there a better structure than List<KVP>? I've never used it before
senox13
senox132y ago
Depending on the performance requirements of this code, I'd be inclined to suggest just implementing your own MultiDictionary type. Sounds like it'd make for a cleaner end product
Ted Bunny
Ted Bunny2y ago
Yeah, I'm really not liking the clunky syntax of the KVP stuff. I'll give that a shot. Thanks, all!
Want results from more Discord servers?
Add your server
More Posts
MAUI navigation to new page with injected viewModelIf you think this belong more into #mobile channel I can move, but I think some of you who are morecatching an exception in an async Task [Answered]I can't seem to catch an exception that is thrown in an async Task, I put try/catch within the asyncpass data onclick from one page to another page in asp nethi all, im trying to redirect a page from **Main Page** to **Sub Page** when i click an item on **MASP NET Core default DI-Container, how pass in constructor not-registered parameter? [Answered]I want to create a Model class using a DI container, services registered in the container are passedShould I return the whole created object in POST or just return the id of that object ?When I creating a post method I find myself repeat what I did in GetById Should I just return the Iasp net cshtml javascript filehi all, i have an asp net project (SimpleApp) and in a cshtml file of my **SimpleApp ** project i trChange Visual Studio suggetions with custom analysersHiya.. ohh discords new "forum" channels are super useful for this huh?. anyway. So I managed to impProgram won’t run with just .net runtime [Answered]So my program that I published and is targeting .net 6 won’t run when the pc has just .net 6 runtimeNullReferenceException Object reference not set to an instance of an object```cs List<Effects> effectsList = activePlayerEffects[targetPlayer] ?? new List<Effects>(); ``` someDbContext.SaveChangesAsync has no effect on the collection of changed objectsHi. I get products collection from dbContext, change some values and want to save it in the database