Event : Visual Studio Users Community Japan #1
Date : 2019/09/14
ソフトウェア/サービス開発において最も後回しにされるものの代表が「パフォーマンスの向上」です。C#/.NET の最大の武器は開発生産性ですが、C# 7.0 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
Event : Visual Studio Users Community Japan #1
Date : 2019/09/14
ソフトウェア/サービス開発において最も後回しにされるものの代表が「パフォーマンスの向上」です。C#/.NET の最大の武器は開発生産性ですが、C# 7.0 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
This document provides information about an event on asynchronous programming and user interface/experience design. It introduces the speaker as Takumi Suzuki, a Microsoft MVP for Visual C#, and provides links to his blog and an article about asynchronous methods in C# 5.0 and VB11.0. The document discusses the goal of "non-stop" experiences across different client devices and points of great UI/UX like beauty, usability, simplicity, and speed. It also briefly touches on techniques for asynchronous programming and some of the difficulties like callbacks, exclusivity, and deadlocks.
This document discusses developing C# applications on the Surface using limited tools like Notepad and PowerShell. It notes some limitations of PowerShell like not being able to load certain DLLs or create custom types. It considers remote options like using RemoteApp or remote debugging via Azure or VPN. The overall message is that basic C# development is possible directly on the Surface with minimal tools.
9. var bin = 0b1011; //--- New!!
var dec = 123;
var hex = 0x1F;
Binary Literals
利用可能な
数字:
0 / 1
接頭辞:
0b / 0B2 進数表記
10. var bin = 0b1100_1010; //--- 4ビットずつ
var dec = 12_345_678; //--- 通貨の区切りっぽく
var hex = 0x33_ff_cc; //--- RGB 区切り
Digit Separators
先頭 / 末尾
以外は
いくつでも
自由な
桁区切り
11. if (int.TryParse("123", out var value));
Console.WriteLine(value);
Out Variable Declarations
スコープの
極狭化
式の途中で
変数宣言
12. static void Main()
{
IEnumerable<T> twice<T>(T x)
where T : struct
{
yield return x;
yield return x;
}
var xs = twice(12.3);
}
Local Functions
Generics
yield
なんでもOK
関数内で
のみ使える
関数
13. static void Main()
{
var a = new int[] { 0, 1, 2, 3, 4 };
ref var d = ref GetValue(a);
d = 5;
// 0, 1, 5, 3, 4
}
static ref int GetValue(int[] b)
{
ref var c = ref b[2];
return ref c;
}
Ref Locals / Ref Returns
メモリ効率
向上
参照受け
参照返し
14. (int sum, int count) Tally(IEnumerable<int> list)
{
var s = 0; var c = 0;
foreach (var x in list)
{
s += x;
c++;
}
return (s, c);
}
var t = Tally(new []{ 1, 2, 3 });
Tuples
ValueTuple
の糖衣構文
多値戻り値
サポート
15. //--- タプル型のインスタンスを
var t = (123, "abc");
//--- 変数に分解
(int x, string y) = t;
(var x, var y) = t;
var (x, y) = t;
Deconstructions
入れ子もOK
任意の型を
分解可能
16. より狭い
スコープ
//--- 定数マッチング
var v = x is 123;
//--- 型マッチング
object x = "abc";
if (x is string v)
{
//--- 何か v を用いた処理
}
Type Switch - is -
より簡易で
厳密な判定
17. object x = 123;
switch (x)
{
case "abc":
break;
case int v when 100 < v: //--- v が 100 より大きいとき
break;
case int v: //--- v が 100 以下のとき
break;
}
Type Switch - switch -
より強力な
条件分岐
when 句での
条件設定
(case guard)
計画の一部
のみを
搭載予定