I am checking to see if a Directory exists with this code:
while (Directory.Exists(currentDirectory + year.ToString))
{
// do stuff
year++;
}
year is a normal integer, currentDirectory a string. Unfortunately this Operation gives me the "Operator '+' cannot be applied to operands of type "string" and "method group" error mesage. I don't really want to create a new string on each Iteration when I only need to increment.
ToString
is a method. You need to invoke it; so you're missing ()
after ToString
.
Change it to
while (Directory.Exists(currentDirectory + year.ToString()))
{
// do stuff
year++;
}
And it should work :)
Missing brackets ()
after ToString
. You need to change it to the following:
while (Directory.Exists(currentDirectory + year.ToString()))
{
// do stuff
year++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With