C
C#14mo ago
Hedreon

✅ Operator ! cannot be applied to type string

yeah I cannot really test this properly since Visual Studio is not available in my current operating system. Though, I am using an online compiler to debug this in some way, shape or form. I haven't coded in C# in so long but I am contributing to an installer made in C# so how do I check if a special folder exists, and if not, add a different folder to the shortcutPaths?
if (FPM.Main.ShortcutStartMenu.Checked)
{
if (!Environment.GetFolderPath(Environment.SpecialFolder.Programs))
{
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
}
else
{
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
}
}
if (FPM.Main.ShortcutStartMenu.Checked)
{
if (!Environment.GetFolderPath(Environment.SpecialFolder.Programs))
{
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
}
else
{
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
}
}
I'm just so used to coding in Java that I use the ! operator when I mean something "isn't there."
12 Replies
Pobiega
Pobiega14mo ago
prefixing everything with ! is a javascript thing
Hedreon
HedreonOP14mo ago
and a java thing in some scenarios
Pobiega
Pobiega14mo ago
since "!undefined" is false no in both java and C#, !true == false java does not have truth conversions the way JS has
Hedreon
HedreonOP14mo ago
no I mean in Java you can use the ! operator in a bit more scenarios than C#
Pobiega
Pobiega14mo ago
Show me an example
Hedreon
HedreonOP14mo ago
I know it because I've programmed in Java more than I did with C#
Pobiega
Pobiega14mo ago
where it works in java but not in C#
Hedreon
HedreonOP14mo ago
mainly in booleans for sure okay maybe it's the same in both languages I'll admit that
Pobiega
Pobiega14mo ago
It is, unless Java recentyl added some weird stuff 😛 so its common with methods that return bools but you cant do it on Environment.GetFolderPath because that returns a string
var path = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
if(!Directory.Exists(path))
{
path = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
}
shortcutPaths.Add(path);
var path = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
if(!Directory.Exists(path))
{
path = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
}
shortcutPaths.Add(path);
Hedreon
HedreonOP14mo ago
agreed, that's where the confusion could come from okay thanks guys very amazing! 👍 How do I mark this as solved and automatically close post?
Pobiega
Pobiega14mo ago
/close
Hedreon
HedreonOP14mo ago
okay thanks
Want results from more Discord servers?
Add your server