{"id":2550,"date":"2020-11-11T14:06:14","date_gmt":"2020-11-11T05:06:14","guid":{"rendered":"https:\/\/took.jp\/?p=2550"},"modified":"2020-11-11T18:00:43","modified_gmt":"2020-11-11T09:00:43","slug":"unity%e3%81%a7%e3%81%af%e5%8b%95%e4%bd%9c%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%e3%81%ae%e3%81%ab%e5%ae%9f%e6%a9%9f%e3%81%a7%e5%8b%95%e4%bd%9c%e3%81%97%e3%81%aa%e3%81%8f%e3%81%aa%e3%81%a3%e3%81%9f","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/unity%e3%81%a7%e3%81%af%e5%8b%95%e4%bd%9c%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%e3%81%ae%e3%81%ab%e5%ae%9f%e6%a9%9f%e3%81%a7%e5%8b%95%e4%bd%9c%e3%81%97%e3%81%aa%e3%81%8f%e3%81%aa%e3%81%a3%e3%81%9f\/","title":{"rendered":"Unity\u3067\u306f\u52d5\u4f5c\u3057\u3066\u3044\u305f\u306e\u306b\u5b9f\u6a5f\u3067\u52d5\u4f5c\u3057\u306a\u304f\u306a\u3063\u305f\u5834\u5408\u306b\u3001\u78ba\u8a8d\u3059\u3079\u304d\u7b87\u6240"},"content":{"rendered":"<h2>Unity\u3067\u306f\u52d5\u4f5c\u3057\u3066\u3044\u305f\u306e\u306b\u5b9f\u6a5f\u3067\u52d5\u4f5c\u3057\u306a\u304f\u306a\u3063\u305f\u5834\u5408\u306b\u3001\u78ba\u8a8d\u3059\u3079\u304d\u7b87\u6240<\/h2>\n<p>unity\u3067\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3057\u3066\u3044\u305f\u30b2\u30fc\u30e0\u3092\u30d3\u30eb\u30c9\u3057\u3001\u5b9f\u6a5f\u3067\u30c6\u30b9\u30c8\u3092\u884c\u306a\u3063\u305f\u5834\u5408\u306b\u52d5\u4f5c\u3057\u306a\u304f\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u969b\u306e\u539f\u56e0\u3068\u306a\u3063\u305f\u7b87\u6240\u3001\u5bfe\u51e6\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u539f\u56e0\u306f\u3001foreach\u3067\u56de\u3059\u5024\u306bnull\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3053\u3068\u3067\u3057\u305f\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bnull\u3092\u542b\u3080\u914d\u5217\u3092foreach\u3067\u56de\u3059\u3088\u3046\u306a\u72b6\u6cc1\u3067\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">public string[] items = {\"item1\", null , \"item3\"};\r\nforeach (var item in items)\r\n{\r\n    Debug.Log(item);\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u89e3\u6c7a\u65b9\u6cd5\uff11<\/h3>\n<p>\u5bfe\u51e6\u6cd5\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5f62\u3067\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">public string[] items = {\"item1\", null , \"item3\"};\r\nforeach (var item in items ?? Enumerable.Empty&lt;T&gt;())\r\n{\r\n    Debug.Log(item);\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>??\u6f14\u7b97\u5b50\u306f\u3001null\u5408\u4f53\u6f14\u7b97\u5b50\u3068\u3082\u547c\u3073\u3001null\u5024\u3067\u3042\u308b\u5834\u5408\u306b\u306f\u3001\u53f3\u5074\u306e\u5024\uff08<strong>Enumerable.Empty&lt;T&gt;()<\/strong>\uff09\u3092\u8fd4\u3059\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>??\u6f14\u7b97\u5b50\u53c2\u8003\uff1a<a href=\"https:\/\/docs.microsoft.com\/ja-jp\/previous-versions\/ms173224(v=vs.120)\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/ja-jp\/previous-versions\/ms173224(v=vs.120)<\/a><\/p>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/tiratom.hatenablog.com\/entry\/2018\/12\/16\/foreach%E3%81%AE%E6%99%82%E3%81%AENullReferenceException%E3%82%92%E5%9B%9E%E9%81%BF%E3%81%99%E3%82%8B\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/tiratom.hatenablog.com\/entry\/2018\/12\/16\/foreach%E3%81%AE%E6%99%82%E3%81%AENullReferenceException%E3%82%92%E5%9B%9E%E9%81%BF%E3%81%99%E3%82%8B<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u307e\u305f\u3001\u3053\u306e\u72b6\u614b\u3060\u3068\u5229\u7528\u3057\u3065\u3089\u3044\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">public static IEnumerable&lt;T&gt; OrEmptyIfNull&lt;T&gt;(this IEnumerable&lt;T&gt; collection)\r\n{\r\n    return collection ?? Enumerable.Empty&lt;T&gt;();\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u5229\u7528\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5f62\u3067\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">public string[] items = {\"item1\", null , \"item3\"};\r\nforeach (var item in items.OrEmptyIfNull())\r\n{\r\n    Debug.Log(item);\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3082\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u5834\u5408\u306b\u306f\u3001using\u5ba3\u8a00\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">The name 'Enumerable' does not exist in the current context [Assembly-CSharp]csharp(CS0103)<\/code><\/pre>\n<pre class=\"line-numbers\"><code class=\"language-other\">using System.Linq; <\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u89e3\u6c7a\u6cd52<\/h3>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u65b9\u6cd5\uff08\u89e3\u6c7a\u6cd5\uff11\uff09\u3067\u306f\u3001null\u5024\u304c\u5165\u3063\u305f\u5834\u5408\u306b\u3001\u305d\u306e\u578b\u306eempty\u3092\u8fd4\u3059\u3068\u3044\u3046\u51e6\u7406\u3067\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001null\u3092\u9664\u53bb\u3057\u305f\u914d\u5217\u3092\u518d\u751f\u6210\u3059\u308b\u5834\u5408\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u65b9\u6cd5\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">public static IEnumerable&lt;T&gt; WhereNotNull&lt;T&gt;(this IEnumerable&lt;T&gt; source) \r\n    where T : class \r\n{\r\n    if (source == null) \r\n    { \r\n        return Enumerable.Empty&lt;T&gt;(); \r\n    } \r\n    return source.Where(x =&gt; x != null);\r\n}<\/code><\/pre>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/qiita.com\/shima_\/items\/060fd3f35ea59ecd576a\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/qiita.com\/shima_\/items\/060fd3f35ea59ecd576a<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u79c1\u306e\u5834\u5408\u306f\u3001\u914d\u5217\u6570\u304b\u3089\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u3066\u3044\u305f\u305f\u3081\u3001null\u3092\u9664\u53bb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u3053\u3061\u3089\u306e\u65b9\u6cd5\u3092\u3068\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3082\u3057\u3001null\u5224\u5b9a\u304c\u6b63\u3057\u304f\u884c\u3048\u306a\u3044\u5834\u5408\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u304c\u53c2\u8003\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div class=\"sc_getpost\"><a class=\"clearfix\" href=\"https:\/\/took.jp\/tech-blog\/unity-null%e3%81%aa%e3%81%ae%e3%81%abnull%e5%88%a4%e5%ae%9a%e3%81%ab%e5%bc%95%e3%81%a3%e3%81%8b%e3%81%8b%e3%82%89%e3%81%aa%e3%81%8f%e3%81%a6%e8%ba%93%e3%81%84%e3%81%9f\/\" ><div class=\"sc_getpost_thumb post-box-thumbnail__wrap\"><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODdhAQABAPAAAN3d3QAAACwAAAAAAQABAAACAkQBADs=\" width=\"100\" height=\"100\" alt=\"Unity null\u306a\u306e\u306bnull\u5224\u5b9a\u306b\u5f15\u3063\u304b\u304b\u3089\u306a\u304f\u3066\u8e93\u3044\u305f\" loading=\"lazy\" data-src=\"https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2020\/11\/E-24-150x150.jpg\" class=\"lazyload\"><\/div><div class=\"title\">Unity null\u306a\u306e\u306bnull\u5224\u5b9a\u306b\u5f15\u3063\u304b\u304b\u3089\u306a\u304f\u3066\u8e93\u3044\u305f<\/div><div class=\"date\">2020.11.11<\/div><div class=\"substr\">Unity null\u306a\u306e\u306bnull\u5224\u5b9a\u306b\u5f15\u3063\u304b\u304b\u3089\u306a\u304f\u3066\u8e93\u3044\u305f \u79c1\u304c\u3084\u308a\u305f\u304b\u3063\u305f\u3053\u3068 inspector\u304b\u3089\u53d7\u3051\u53d6\u3063\u305f\u753b\u50cf\u30ea\u30b9\u30c8\u304b\u3089\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3002 \u3082\u3057\u3001\u30ea\u30b9\u30c8\u5185\u306b\u672a\u8a2d\u5b9a\u9805\u76ee\uff08null\uff09\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u306f\u3001\u305d\u308c\u3092\u9664\u5916\u3057\u305f\u914d\u5217\u3092\u518d\u751f\u6210\u3057\u3001\u95a2\u6570\u306b\u5f15\u304d\u6e21\u3059\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3046\u6d41\u308c\u3067\u3059\u3002  null\u3092\u9664\u5916...<\/div><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Unity\u3067\u306f\u52d5\u4f5c\u3057\u3066\u3044\u305f\u306e\u306b\u5b9f\u6a5f\u3067\u52d5\u4f5c\u3057\u306a\u304f\u306a\u3063\u305f\u5834\u5408\u306b\u3001\u78ba\u8a8d\u3059\u3079\u304d\u7b87\u6240 unity\u3067\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3057\u3066\u3044\u305f\u30b2\u30fc\u30e0\u3092\u30d3\u30eb\u30c9\u3057\u3001\u5b9f\u6a5f\u3067\u30c6\u30b9\u30c8\u3092\u884c\u306a\u3063\u305f\u5834\u5408\u306b\u52d5\u4f5c\u3057\u306a\u304f\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3057\u305f\u3002 \u305d\u306e\u969b\u306e\u539f\u56e0\u3068\u306a\u3063\u305f\u7b87\u6240\u3001\u5bfe\u51e6\u6cd5\u3092\u30e1\u30e2\u3002 &#038;nbsp\u2026<\/p>\n","protected":false},"author":3,"featured_media":2551,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"class_list":["post-2550","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/2550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=2550"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/2550\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/2551"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=2550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=2550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=2550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}