File exist bug

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
Not working

C#:
string upVoteAccountPath = project.Directory + @"\Data\" + "Test.txt";
// Check if accounts file exist
bool exist = File.Exists(upVoteAccountPath);

if(exist = false)
{
    project.SendInfoToLog("File does not exist", false);
}

Working

C#:
string upVoteAccountPath = project.Directory + @"\Data\" + "Test.txt";

if(!File.Exists(upVoteAccountPath))
{
    project.SendInfoToLog("File does not exist", false);
}
 

darkdiver

Administrator
Команда форума
Регистрация
13.01.2009
Сообщения
2 284
Благодарностей
2 728
Баллы
113
should be
C#:
string upVoteAccountPath = project.Directory + @"\Data\" + "Test.txt";
// Check if accounts file exist
bool exist = File.Exists(upVoteAccountPath);

if(!exist)
{
    project.SendInfoToLog("File does not exist", false);
}
or

C#:
string upVoteAccountPath = project.Directory + @"\Data\" + "Test.txt";
// Check if accounts file exist
bool exist = File.Exists(upVoteAccountPath);

if(exist==false)
{
    project.SendInfoToLog("File does not exist", false);
}
you should use == to compare not =
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
@darkdiver I'm sorry I know I'm not expert in C# but I have used just one = to compare boolean before and all was just fine. I even getting error if you compare string with one = like: Error in action "CS0029" "Cannot implicitly convert type 'string' to 'bool'". [Row: 1; Column: 4]

And also this way is working just fine:

C#:
bool test = true;
if(test = true) project.SendInfoToLog("Right", true);
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)