C
C#8mo ago
cheeze2000

How can my out parameter be nullable?

Not sure what's going on, if anyone can give me a hand on this one
No description
11 Replies
cheeze2000
cheeze2000OP8mo ago
so i have a dictionary called _names and the type is Dictionary<string, Ty> Ty is a class, name is a string
Angius
Angius8mo ago
The Try pattern requires the out parameter to be nullable If the method returns false, the out has to be something, and the only option is a null
cheeze2000
cheeze2000OP8mo ago
ohhh
Angius
Angius8mo ago
There's an attribute on it, [NotNullWhen] probably, that makes it so that it's not null when the return is true, yes But the type is still nullable That's why, most often, you see people use out var foo instead of out TheType foo
cheeze2000
cheeze2000OP8mo ago
Dictionary<string, int> test = [];

if (test.TryGetValue("", out int num))
{
// what is num here? zero?
}
Dictionary<string, int> test = [];

if (test.TryGetValue("", out int num))
{
// what is num here? zero?
}
Angius
Angius8mo ago
$tias
cheeze2000
cheeze2000OP8mo ago
hehe wait it doesn't even work because there's no such entry in the dictionary oh it's 0, nice so it's just the default
Angius
Angius8mo ago
Yep
cheeze2000
cheeze2000OP8mo ago
thanks
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server