Skip to content

Commit 6115596

Browse files
author
y-yamasaki
committed
Merge branch 'develop'
2 parents 88a0ac2 + 8b49a5b commit 6115596

10 files changed

Lines changed: 1218 additions & 63 deletions

File tree

WebSite/assets/data/blogList.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
[
2+
{
3+
"id": "blog_00022",
4+
"title": "C#14の新機能の解説",
5+
"date": "2025-12-19T00:00:00.000Z",
6+
"category": "Unity",
7+
"description": "C#14で導入された注目の機能を実例を交えてわかりやすく解説します。",
8+
"tags": [
9+
"unity",
10+
"csharp"
11+
],
12+
"thumbnail": "assets/img/csharp_icon.png",
13+
"contentPath": "blog/blog_00022.html",
14+
"recommended": true
15+
},
216
{
317
"id": "blog_00023",
418
"title": "Zed IDE setting.jsonのすすめ",

WebSite/assets/data/blogList_en.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
[
2+
{
3+
"id": "blog_00022",
4+
"title": "C#14:New Features Explained",
5+
"date": "2025-12-19T00:00:00.000Z",
6+
"category": "Unity",
7+
"description": "An easy-to-understand, example-driven explanation of notable features introduced in C# 14.",
8+
"tags": [
9+
"unity",
10+
"csharp"
11+
],
12+
"thumbnail": "assets/img/csharp_icon.png",
13+
"contentPath": "blog/en/blog_00022.html",
14+
"recommended": true
15+
},
216
{
317
"id": "blog_00023",
418
"title": "Recommended Zed setting.json",

WebSite/assets/img/csharp_icon.png

13.4 KB
Loading

WebSite/blog/blog_00022.html

Lines changed: 458 additions & 0 deletions
Large diffs are not rendered by default.

WebSite/blog/blog_00023.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ <h2 id="まとめ">まとめ</h2><p>setting.jsonはケースによって都度
399399
</div>
400400
</div>
401401

402-
<div class="post-detail__nav post-detail__nav--bottom"><a href="blog_00020.html" class="btn btn--prev">← 試行錯誤のGemini 3…</a><a href="../blog.html" class="btn btn--back">← ブログ一覧へ戻る</a></div>
402+
<div class="post-detail__nav post-detail__nav--bottom"><a href="blog_00020.html" class="btn btn--prev">← 試行錯誤のGemini 3…</a><a href="../blog.html" class="btn btn--back">← ブログ一覧へ戻る</a><a href="blog_00022.html" class="btn btn--next">C#14の新機能の解説 →</a></div>
403403
</article>
404404
</div>
405405
<aside class="post-sidebar">

WebSite/blog/en/blog_00022.html

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.

WebSite/blog/en/blog_00023.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ <h2 id="conclusion">Conclusion</h2><p><code>setting.json</code> tends to be some
402402
</div>
403403
</div>
404404

405-
<div class="post-detail__nav post-detail__nav--bottom"><a href="blog_00020.html" class="btn btn--prev">← Trial and Err…</a><a href="../blog.html" class="btn btn--back">← Back to Blog</a></div>
405+
<div class="post-detail__nav post-detail__nav--bottom"><a href="blog_00020.html" class="btn btn--prev">← Trial and Err…</a><a href="../blog.html" class="btn btn--back">← Back to Blog</a><a href="blog_00022.html" class="btn btn--next">C#14:New Feat… →</a></div>
406406
</article>
407407
</div>
408408
<aside class="post-sidebar">
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
title: C#14:New Features Explained
3+
date: 2025-12-19
4+
category: Unity
5+
description: An easy-to-understand, example-driven explanation of notable features introduced in C# 14.
6+
tags: [unity, csharp]
7+
recommended: true
8+
thumbnail: assets/img/csharp_icon.png
9+
---
10+
11+
Hello! I'm Pan-kun.
12+
13+
This time I'd like to pick up and introduce several features from the C# 14 documentation that was published at the end of last month.
14+
Official reference:
15+
[!CARD](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14)
16+
17+
## C# 14 — New Features
18+
19+
### The `field` keyword
20+
21+
Many developers commonly use fields and properties in patterns like the following. The main purpose, as you know, is encapsulation. With this new feature, you can now write:
22+
23+
```csharp
24+
// before
25+
private string m_foo;
26+
public string Foo
27+
{
28+
get => m_foo;
29+
private set => m_foo = value;
30+
// If you wanted to add a null check:
31+
// ?? throw new ArgumentNullException(nameof(value))
32+
}
33+
34+
// after
35+
public string Foo
36+
{
37+
get;
38+
set => field = value;
39+
}
40+
```
41+
42+
For developers using an IDE with IntelliSense, many type `m_` and rely on completion, so whether this is helpful depends on coding style. If you group members with regions or care about explicit naming for readability, you might prefer the traditional pattern. For teams with well-defined coding conventions, choose whichever fits your workflow.
43+
44+
The docs also explain how to handle naming conflicts with existing symbols named `field`. However, if you find a symbol actually named `field` in a codebase, consider running `git blame` to see who added it and proceed cautiously.
45+
46+
> Reading code of a type that contains a symbol named `field` can cause breaking changes or confusion.
47+
> You can disambiguate between the `field` keyword and an identifier by using `@field` or `this.field`, or rename the current `field` symbol to make distinctions clearer.
48+
49+
[!CARD](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14#the-field-keyword)
50+
51+
### Extension members
52+
53+
This is the feature related to the familiar `this ClassName valueName` extension-method parameter syntax.
54+
55+
```csharp
56+
public class Foo
57+
{
58+
public int hoge = 1;
59+
}
60+
61+
// before
62+
public static class FooExtensions
63+
{
64+
public static int BeforeExtension(this Foo foo) => foo.hoge;
65+
}
66+
67+
// after
68+
public static class FooExtensions
69+
{
70+
extension(Foo foo)
71+
{
72+
public int AfterExtension() => foo.hoge;
73+
}
74+
}
75+
```
76+
77+
Benefits:
78+
79+
- You no longer need to explicitly declare the instance parameter for each extension member.
80+
- Placing members inside an `extension` block makes the code visually clearer.
81+
- You can declare extension properties.
82+
- You can also declare extension operators.
83+
84+
For more details, see the official docs:
85+
[!CARD](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14#extension-members)
86+
87+
### Null-conditional assignment
88+
89+
```csharp
90+
public class Hoge
91+
{
92+
public string? Name { get; set; } = null;
93+
}
94+
95+
string GetName() => "Pankun";
96+
97+
void Foo(Hoge? hoge)
98+
{
99+
// before
100+
if (hoge is not null) // Null check can be simplified (IDE0031)
101+
hoge.Name = GetName();
102+
103+
// after
104+
hoge?.Name = GetName();
105+
}
106+
```
107+
108+
Benefits:
109+
110+
- Reduces nesting.
111+
- Improves readability.
112+
113+
### Partial members
114+
115+
```csharp
116+
// Foo.cs
117+
public partial class Foo
118+
{
119+
// constructor implementation
120+
public partial Foo()
121+
{
122+
Hoge();
123+
}
124+
125+
// add member implementation
126+
private partial void Hoge() => Console.WriteLine("Partial Hoge");
127+
}
128+
129+
// Foo.members.cs
130+
public partial class Foo
131+
{
132+
// You can add declarations here:
133+
// constructor declaration
134+
// static is not supported
135+
public partial Foo(); // Success
136+
private partial void Hoge(); // Success
137+
}
138+
```
139+
140+
This helps avoid the "How is this call valid when there's no definition here?" confusion.
141+
142+
### nameof support for unbound generic types
143+
144+
```csharp
145+
public static void ShowExample()
146+
{
147+
// Before
148+
Console.WriteLine(nameof(List<int>)); // List<int>
149+
150+
// After
151+
// The argument to nameof can be an unbound generic type.
152+
Console.WriteLine(nameof(List<>)); // List
153+
// NOTE: Use unbound generic type (IDE0340)
154+
Console.WriteLine(nameof(List<int>)); // List<int>
155+
}
156+
```
157+
158+
This allows broader kinds of name-based checks. (I also learned that a generic type without its type arguments specified is called an "unbound generic type".)
159+
160+
## .NET 10
161+
162+
There are other features added in C# 14, but .NET also received several improvements recently, so I'll briefly touch on one of them.
163+
164+
For details, see:
165+
[!CARD](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-10/overview)
166+
167+
### Shebang
168+
169+
You can now add a shebang to run a file as a script. This eliminates the need to create a project or write a Main method for quick scripts.
170+
171+
```csharp
172+
#!/usr/bin/env -S dotnet run
173+
Console.WriteLine("Hoge");
174+
```
175+
176+
I also heard there were improvements in Blazor.
177+
178+
## Conclusion
179+
180+
Although still in preview, these features seem quite promising for private and experimental coding. I expect to use many of them frequently — give them a try!
Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: C#14の新機能の解説
3-
date: 2025-12-12
4-
category: C#
5-
description:
6-
tags: [Gemini, Copilot, API]
3+
date: 2025-12-19
4+
category: Unity
5+
description: C#14で導入された注目の機能を実例を交えてわかりやすく解説します。
6+
tags: [unity, csharp]
77
recommended: true
8-
thumbnail: assets/img/gemini_icon.png
8+
thumbnail: assets/img/csharp_icon.png
99
---
1010

1111
こんにちは!パン君です。
@@ -14,7 +14,9 @@ thumbnail: assets/img/gemini_icon.png
1414
公式はこちら
1515
[!CARD](https://learn.microsoft.com/ja-jp/dotnet/csharp/whats-new/csharp-14)
1616

17-
## field キーワード
17+
## C#14新機能
18+
19+
### field キーワード
1820

1921
よくフィールドとプロパティを利用して下記のような記述を多様する方がいるかと思います。
2022
これの目的はご存知の通り カプセル化が主な目的です。
@@ -54,7 +56,7 @@ IntelliSense前提のコーディングをしていない人とかなら良い
5456
5557
[!CARD](https://learn.microsoft.com/ja-jp/dotnet/csharp/whats-new/csharp-14#the-field-keyword)
5658

57-
## 拡張メンバー
59+
### 拡張メンバー
5860

5961
よく引き数に `this ClassName valueName` と記述するあれですね
6062

@@ -90,7 +92,7 @@ public static class FooExtensions
9092
他詳細は下記の公式参照
9193
[!CARD](https://learn.microsoft.com/ja-jp/dotnet/csharp/whats-new/csharp-14#extension-members)
9294

93-
## Null 条件付き割り当て
95+
### Null 条件付き割り当て
9496

9597
```csharp
9698
public Class Hoge
@@ -116,7 +118,7 @@ void Foo(Hoge? hoge)
116118
- ネスト節約
117119
- 上に続いて可読性向上
118120

119-
## Partialメンバー
121+
### Partialメンバー
120122

121123
```csharp
122124
// Foo.cs
@@ -146,7 +148,7 @@ public partial class Foo
146148
これで 「これ定義無いけどなんで呼べているんだ?」 とならなくて済みます。
147149

148150

149-
## nameofが未バインドジェネリック型に対応
151+
### nameofが未バインドジェネリック型に対応
150152

151153
```csharp
152154
public static void ShowExample()
@@ -157,11 +159,35 @@ public static void ShowExample()
157159
// After
158160
// nameof する引数はバインドされていないジェネリック型にすることができます。
159161
Console.WriteLine(nameof(List<>)); // List
160-
// NOTE: Use unbound generic type (IDE0340) の警告が出ます。
161-
Console.WriteLine(nameof(List<int>)); // List<int>
162+
// NOTE: Use unbound generic type (IDE0340)
163+
Console.WriteLine(nameof(List<int>)); // List<int>
162164
}
163165
```
164166

165-
これにより幅広く判定が取れるようになりました
167+
これにより幅広く判定が取れるようになりました。
168+
(型引き数を埋めていないジェネリック型を unbound(未束縛) って言ったりすることを今回初めて知りました。)
169+
170+
## .NET 10
171+
172+
他にもC#14で追加された機能はあるのですが、
173+
.NET側にもいくつか昨日が追加されているのでそちらについても少しふれておきます。
174+
175+
詳しくは下記参照
176+
[!CARD](https://learn.microsoft.com/ja-jp/dotnet/core/whats-new/dotnet-10/overview)
177+
178+
### shebang
179+
180+
下記のように記載することでファイルベースでスクリプトを実行できるようになりました。
181+
これによりプロジェクトを作成したり、Mainメソッドを作成したりなどなどする必要がなくなります。
182+
183+
```csharp
184+
#!/usr/bin/env -S dotnet run
185+
Console.WriteLine("Hoge");
186+
```
187+
188+
他にもBlazorでで改善があったらしいのです。
189+
190+
## まとめ
166191

167-
#
192+
まだプレビュー版ですがプライベートのコーディングではかなり使用頻度に期待できる機能が追加された印象です。
193+
是非使っていきたいですね。

0 commit comments

Comments
 (0)