Skip to content

Instantly share code, notes, and snippets.

@shibayan
Last active December 14, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibayan/5047907 to your computer and use it in GitHub Desktop.
Save shibayan/5047907 to your computer and use it in GitHub Desktop.
やりたいこと:
・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