我有一个Asp.Net MVC应用程序运行框架版本.NET 4.5,我使用的是VS2017 pro版本.用户可以上传附件,包括但不限于:
- Excel
- 单词
- 幻灯片演示文稿软件
- jpeg
- 巴布亚新几内亚
所以我有一个private
函数,如下所示:
private string ImageExtension(string path)
{
string noImagePath = HttpContext.Current.Server.MapPath("~/Content/images/Template/No-Image-Available-100x100.jpg");
string fileExtension = System.IO.Path.GetExtension(path);
switch (fileExtension)
{
case ".jpg":
case ".jpeg":
case ".gif":
case ".巴布亚新几内亚":
return path;
default:
return noImagePath;
}
}
正如你所见,它非常简单,不做任何花哨的事情.因为我只在一个地方使用了它,所以我考虑使用本地函数的新C#7特性.所以我继续创建了我的主要函数,如下所示,并在其中添加了ImageExtension(string path)
个.
public void BugInfo(HttpPostedFileBase file)
{
if(file != null && file.ContentLength > 0)
{
string fileName = file.FileName;
string directoryPath = "directory path";
//save path of
string savePath = System.IO.Path.Combine(directoryPath, fileName);
string testString = ImageExtension(savePath);
string ImageExtension(string path)
{
string noImagePath = HttpContext.Current.Server.MapPath("~/Content/images/Template/No-Image-Available-100x100.jpg");
string fileExtension = System.IO.Path.GetExtension(path);
switch (fileExtension)
{
case ".jpg":
case ".jpeg":
case ".gif":
case ".巴布亚新几内亚":
return path;
default:
return noImagePath;
}
}
}
//save values to db here
}
使用上面的代码,我的项目构建时没有任何错误.一旦我达到F5
或Ctrl + F5
,我就会看到下面的错误屏幕
如果我判断ErrorList
,看看是否有任何错误,我一点都没有,正如你在下面看到的.
有人能告诉我我哪里出错了吗?我是否必须更改任何设置或需要包括任何其他DLL才能使用C#7功能.
看看100答案,似乎所有的C#7功能都可以使用.净4.5