尽可能缩短字符串并分配给变量

I have a string MTopic that sometimes is more than 50 characters, sometimes is less. So I have added this type of code:

if (MTopic.Length >= 50)
{
  Console.WriteLine(MTopic.Substring(0, 50));
  var MTopicShort = MTopic.Substring(0, 50);
}
else
{
  Console.WriteLine(MTopic);
  var MTopicShort = MTopic;
}

I want to use MTopicShort later in my code:

FilesAction(MCountry, MTopicShort, MDeadline);

但是,Visual Studio给我一个错误:

严重性代码说明项目文件行抑制状态   错误CS0103当前名称'MTopicShort'不存在   语境

我知道这是C#的基础知识,但找不到答案。

评论