ラムダ式が短い場合は2回書くのを避ける方法はありますか?私はこの状況で常に自分自身を見つけ、私が知っている唯一の方法はそれをもう一度書くことです!Short IfでのLambda式の重複を避けるには?
例を挙げると、ここでは文字列の長さをチェックする必要があります。
communications.Select(c => new XElement("node",
new XAttribute("guid", Guid.NewGuid()),
new XAttribute("title", c.CommunicationDetails.Where(x => x.CultureCode == culture).FirstOrDefault().Title.Length < 40 ? c.CommunicationDetails.Where(x => x.CultureCode == culture).FirstOrDefault().Title : c.CommunicationDetails.Where(x => x.CultureCode == culture).FirstOrDefault().Title.Substring(0, 40)),
new XAttribute("isHidden", false))))
のようなものに終わるだろう。Title'が起こるのを待っ 'NullReferenceException'です。 – spender