小编Bib*_*jan的帖子

如何将c#ternary运算符与其他语句结合使用return语句

是否可以在三元运算符中写出这个if语句(c#if的简写)?如果是的话会是什么?

   if (condition)
   {
      return true;
   }
   else
   {
      int a = 2;
   }
Run Code Online (Sandbox Code Playgroud)

提前大家好.非常感谢你.

对不起家伙,如果我困惑你.我试图在这个方法的if else块中使用三元运算符.

public static bool CompareDictionary(this Dictionary<Position, char> 
    dictionary1,
    Dictionary<Position, char> dictionary2, out List<string> wordList)
{
    string str = "";
    wordList = new List<string>();

    foreach (var dic1KeyVal in dictionary1)
    {
        Position d1key = dic1KeyVal.Key;
        char d1Pos = dic1KeyVal.Value;

        bool isFound = false;
        foreach (var dic2KeyVal in dictionary2)
        {
            Position d2key = dic2KeyVal.Key;
            char d2Pos = dic2KeyVal.Value;

            if (d1Pos.Equals(d2Pos) && d1key == d2key)
            {
                isFound = …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
9934
查看次数

标签 统计

c# ×1