美文网首页
.Net Core 返回空数组

.Net Core 返回空数组

作者: Rinaloving | 来源:发表于2023-07-20 16:13 被阅读0次

返回空数组

  • 方式如下:
/*
   Method signature:
   List<T> GetList<T>(); // frequently called and returns an empty list if someCondition is met
*/

return Enumerable.Empty<T>().ToList();
// or
return Array.Empty<T>().ToList();
// or
return new List<T>(0);
// or
return new List<T>();
// or would a proposal for List.Empty<T>() make any sense?
  • 效果


    QQ截图20230721161226.png

相关文章

网友评论

      本文标题:.Net Core 返回空数组

      本文链接:https://www.haomeiwen.com/subject/tgrzudtx.html