1

データテーブルのデータ行を作成する一環として次のステートメントを使用していますが、ラムダステートメントまたはよりエレガントなものを使用して短縮できるかどうか疑問に思っていました。

if (outval(line.accrued_interest.ToString()) == true) 
{ 
temprow["AccruedInterest"] = line.accrued_interest; 
} 
else 
{
temprow["AccruedInterest"] = DBNull.Value;
}

ステートメントは次の方法でチェックされます。

 public static bool outval(string value)
        {
            decimal outvalue;
            bool suc = decimal.TryParse(value, out outvalue);
            if (suc)
            {
                return true;
            }
            else
            {
                return false;
            }


        }
4

4 に答える 4

3

あなたがしたいですか?演算子、ラムダ式は必要ありません。

http://msdn.microsoft.com/en-us/library/ty67wk28.aspx

int input = Convert.ToInt32(Console.ReadLine());
string classify;

// if-else construction.
if (input < 0)
    classify = "negative";
else
    classify = "positive";

// ?: conditional operator.
classify = (input < 0) ? "negative" : "positive";
于 2013-08-14T16:09:56.740 に答える