我正在写以下内容:namespace Converter { public class Converter { public string dnaToRna(string dna) { string rna = ""; foreach(char letter in dna){ letter=='T' ? rna+='U' : rna+=letter; rna+=letter; } return rna; } } }当我用测试调用代码时: namespace Converter { using NUnit.Framework; using System; [TestFixture] public class Test { [Test] public void test() { Converter converter = new Converter(); Assert.AreEqual("UUUU", converter.dnaToRna("TTTT")); } }}它说:src/Solution.cs(9,9): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement但是,如果我将其替换为:namespace Converter { public class Converter { public string dnaToRna(string dna) { string rna = ""; foreach(char letter in dna){ if(letter=='T'){ rna+='U'; }else{ rna+=letter; } } return rna; } }}它有效,为什么?感谢您的帮助😌😌😌。
- 3 回答
- 0 关注
- 284 浏览
添加回答
举报
0/150
提交
取消