Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 变量的值未更新_C#_Variables - Fatal编程技术网

C# 变量的值未更新

C# 变量的值未更新,c#,variables,C#,Variables,我目前正在进行一个项目,该项目将扫描邮箱中的附件,当找到一个附件时,它将被放置在用户目录中。我的问题是,当我检查路径中是否存在文件时,我会更改附件的名称,并添加计数器和时间戳,这样就不会写得太多。但是,当它进入条件并更改文件名时,它从不更新path变量以包含Clean name变量的正确值 string timeProcessed = DateTime.Now.ToString(); byte[] bytefiles = attachment.ContentBytes; string clean

我目前正在进行一个项目,该项目将扫描邮箱中的附件,当找到一个附件时,它将被放置在用户目录中。我的问题是,当我检查路径中是否存在文件时,我会更改附件的名称,并添加计数器和时间戳,这样就不会写得太多。但是,当它进入条件并更改文件名时,它从不更新path变量以包含Clean name变量的正确值

string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);       
string path = employeeStarPath + "\\" + cleanName;
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{                                  
    cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.

}
string timeProcessed=DateTime.Now.ToString();
byte[]bytefiles=attachment.ContentBytes;
字符串cleanName=MakeCleanName(userEmail.Subject,attachment.Name);
字符串路径=employeeStarPath+“\\”+cleanName;
//更新此项以防止同名图像相互覆盖。
if(File.Exists(path))
{                                  

cleanName=Path.GetFileNameWithoutExtension(attachment.Name).ToString()+”(“+计数器+”)+“-”(received-“+timeProcessed.Replace(“:”,”).Replace(“/”,“+”)”)+Path.GetExtension(attachment.Name);我可能不理解你的问题,但你能不能直接调用“string Path=employeeStarPath+”\“+cleanName;”在最后而不是在if之前

string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);       

// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{                                  
    cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.

}

string path = employeeStarPath + "\\" + cleanName;
string timeProcessed=DateTime.Now.ToString();
byte[]bytefiles=attachment.ContentBytes;
字符串cleanName=MakeCleanName(userEmail.Subject,attachment.Name);
//更新此项以防止同名图像相互覆盖。
if(File.Exists(path))
{                                  

cleanName=Path.GetFileNameWithoutExtension(attachment.Name).ToString()+”(“+计数器+”+”)-(接收-“+时间处理过的.Replace(“:”,”).Replace(“/”,“)+”)+Path.GetExtension(attachment.Name);是的,我不得不离开监视器,我将稍微重新构造我的代码,只是要记住另一个可能在我之后出现的人MakeCleanName方法中发生的事情与您在
if(File.Exists(path))中正在做的事情之间有什么区别
block?我想你真的只想执行其中一条语句,这取决于实际发生的情况。是的,正是我所想的,我将在Makeclean方法中执行文件检查,这样看起来会更好。