Skip to content

Instantly share code, notes, and snippets.

@shibayan
Last active Dec 14, 2015
Embed
What would you like to do?
やりたいこと:
・object -> IList<object> への変換
・model が null の時には要素数が 0 の IList<object> にする
思い付いたコード:
初版
var values = new List<string>(((model as IEnumerable) ?? Enumerable.Empty<object>()).Cast<object>().Select(p => p.ToString()));
じんぐるさん提案の修正を入れた
var values = ((model as IEnumerable) ?? new object[0]).Cast<object>().Select(p => p.ToString()).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment