38 Replies
it shows a red line under "Get"
even though i wrote what the youtube guy wrote
The red line could be one of several things. When you mouse over it, what does the popup say?
So there's no
Get()
method on dictionaries
The correct way is to use the indexer NumberTag["endre"]
I'm not sure what tutorial you're following but it's definitely wrongi mean thw website my teacher gave did the same thing too
https://www.c-sharpcorner.com/UploadFile/mahesh/dictionary-in-C-Sharp/
it shows how u can get it using a .Get method
Weird
that article is just plain wrong
that method doesn't exist https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-8.0
Yeah that is... absolutely wrong
you can use the indexer like mg said or TryGetValue if you aren't sure if the value is in the dictionary to avoid throwing an exception
when in doubt always check the official docs and not other websites
im suing my teacher wtf
i wouldn't be surprised if this was just some chatgpt generated trash that they didn't check before posting
my teacher legit gave us the link to that
lazy teacher
the article has other issues like using the
Convert
class to parse numbers and referring to Int16
instead of short
Yeah I was trying to find if there was some historical
Dictionary.Get()
method but the article is from august 2023do i use this instead?
what mg suggested is the simplest solution
wtf, how
but it will throw an exception if the key doesn't exist
i see
No I mean the C# corner article is from aug 2023, so it wouldn't matter if
Get()
existed in an old versionand TryGetValue will js say it doesnt exist?
TryGetValue()
existsTryGetValue returns true or false if it finds the value or not
i see
yes that's what I meant, how did it get that wrong
@Chaqueta ✪ do you have a link to the youtube video?
honestly i think jimmacle might be right that it's chatgpt garbage
uh i tried finidng it but i had my history off TvT
it was from 2017
i feel like i've heard people trash on csharpcorner's quality before
idk if i'm confusing it with another website
I thought it was ok but clearly not
bruh im only dissapointed cus
translates to : use this website to learn about dictionary
ish
gross
i thought i liked him
nvm
aight anyways back to coding
these microsoft learn pages are published by microsoft who maintains C#, so they will always be the best source of truth
.Get sounds like java thing, like with their ArrayList<>s and not allowing anything but array to have an indexer
I have
It's bad