© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
22 replies
UnemployedNinja

Why does this require a cast?

I have this method:
public string JsonSerialize(bool? mini) {
    mini = mini == null ? true : mini;
    JsonSettings.Formatting = mini ? Formatting.None : Formatting.Indented;
    return JsonConvert.SerializeObject(this, JsonSettings);
}
public string JsonSerialize(bool? mini) {
    mini = mini == null ? true : mini;
    JsonSettings.Formatting = mini ? Formatting.None : Formatting.Indented;
    return JsonConvert.SerializeObject(this, JsonSettings);
}

Even though I've null-checked
mini
mini
, VS is still telling me that I need an explicit cast to
bool
bool
on
mini ? Formatting.None : Formatting.Indented
mini ? Formatting.None : Formatting.Indented


Why?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Why does calling the PrintFullName() method require casting it as ((Employee)PTE).PrintFullName() ?
C#CC# / help
2y ago
why does this Not work?
C#CC# / help
3y ago
❔ Why does it do this?
C#CC# / help
3y ago
❔ Why does this not work?
C#CC# / help
3y ago