プログラミング C# - 翔ソフトウェア (Sho's) tag:blog.shos.info,2020://1 2020年08月06日T09:11:05Z C#/.NET/ソフトウェア開発など Movable Type 3.35 [C#]【ライブコーディング】連結リスト LinkedList ‐自作で学ぶコレクションの基礎‐ tag:blog.shos.info,2020://1.937 2020年08月06日T14:59:59Z 2020年08月06日T09:11:05Z YouTube で xin9le さんとコーディング ライブをやりました。 お題... Fujiwo http://www.shos.info YouTubexin9le さんとコーディング ライブをやりました。

お題は、C#連結リスト LinkedList<T>

テストを書きながら少しずつ実装していくというものになっています。

Visual StudioLive ShareLive Unit Testing を使い、2人で快適にコーディングすることができました。

[フレーム] ]]>
「.NET で機械学習/ディープラーニングをやってみよう!」 | MVP パーソナルスポンサー | de:code 2020 tag:blog.shos.info,2020://1.936 2020年07月23日T03:29:15Z 2020年07月23日T03:41:19Z デジタル イベントとして開催された de:code 2020 (6月17日 –... Fujiwo http://www.shos.info デジタル イベントとして開催された de:code 2020 (6月17日 – 7月17日) にMVP パーソナルスポンサーとしてサンプル コードとチュートリアルを提供しました。

【de:code 2020】 Azure Machine Learning Studio と Python と C#/.NET によるディープ ラーニングのサンプル/チュートリアル | GitHub

概要

Azure Machine Learning などで機械学習/ディープラーニングのモデルを作成し、それを .NET の中の ML.NET を利用して使ってみましょう。

チュートリアル形式で説明します。

  1. 話題の TensorFlow を使って機械に学習させよう
  2. Azure Machine Learning を使ってクラウド上で機械学習してみよう
  3. .NET の中の ML.NET を使って学習済みのモデルを使ったアプリケーションを作ってみよう

サンプルコード/ツールの狙い (利用される方にとっての価値)

機械学習/ディープラーニングのモデルを作成するところから、.NET アプリケーションで使うまでの手順を、実際に手を動かしながら学ぶことができます。

]]>
[Event] Microsoft Build 2020 (2020年05月19日-20) tag:blog.shos.info,2020://1.938 2020年06月30日T15:00:00Z 2020年08月09日T02:39:14Z マイクロソフトの最新の技術について、以下のようなオンラインイベントで情報が提供... Fujiwo http://www.shos.info マイクロソフトの最新の技術について、以下のようなオンラインイベントで情報が提供されました。

これらのイベントで公開された/公開予定の技術についてご紹介いたします。

しかく .NET 関連

くろまる One .NET (ひとつの .NET)
しろまる 現在の .NET
しろまる 次の .NET

以前から発表されている通り、次の .NET では次のようになります。

"One .NET" ということで、.NET が現在の .NET Core に統合され、.NET 5 となります。

(注記) .NET 5 に含まれないもの

  • WCF (Windows Communication Foundation)
  • WF (Workflow Foundation)
  • ASP.NET WebForms

ちなみに .NET Framework は 4.8 が最終バージョンです。今後は保守フェーズに入り、機能の新規追加はされなくなります。

.NET Framework のサポート自体は Windows 10 がサポートされている間は続くと思われます。

将来性から考えると、新規に .NET で開発する場合は、.NET Core を用いるべきだと考えられます。

しろまる .NET のロードマップ

上記のとおり、現在ある .NET Framework、.NET Core、Xamarin は一つの .NET に統合されます。

但し、2020 年 11 月の .NET 5 リリース時点では Xamarin の統合はプレビュー扱いです。

.NET 6 で完全に統合される見込みです。

.NET 6 は LTS (Long term support: 長期サポート) 版となる予定なので、新規開発に利用するのは、.NET 6 からが無難かも知れません。

くろまる 新たなマルチプラットフォーム アプリケーション開発方法

Microsoft は既に Windows への囲い込みを行っていませんので、新たな開発方法としては Windows 以外の OS もサポートするマルチ プラットフォームなものを提供していくことになります。

注目すべきは、以下の二つです。

  • MAUI (Multi-platform App UI)
  • Blazor

将来的にはどちらもネイティブアプリケーションも開発できるものですが、MAUI は従来の Windows アプリケーション開発技術の延長にある技術、Blazor は Web アプリケーション開発技術の延長にあり、とりあえずは Web 開発用です。

ひとつずつ説明します。

しろまる MAUI (Multi-platform App UI)

MAUI というアプリケーション開発技術が発表されました。

MAUI の特徴は次の通りです :

  • iOS や Android、Windows など複数のプラットフォームに対応したネイティブなユーザーインターフェイスを実現できる UI フレームワーク
  • 従来の Xamarin Forms の技術の延長
  • .NET 6 Preview (2021 年 11 月頃リリース予定) でリリース予定
  • 全体を C#/.NET で開発
  • UI は XAML (WPF や UWP、Xamarin Forms の UI 言語) ベース

XAML (Extensible Application Markup Language):

  • WPF や UWP、Xamarin Forms の UI 記述用言語
  • 今までは、XAML は WPF や UWP、Xamarin Forms で統一されていなかった
しろまる Blazor

現在すでに Blazor Server という、C# だけで Web アプリケーションが開発できるサーバーサイド技術が .NET で使用できますが、この技術が拡張され、Web アプリケーションだけでなくネイティブアプリケーションも作成できるようになることが予定されています。

Blazor の特徴は次のとおりです:

  • Web 技術の延長
  • 全体を C#/.NET で開発
  • UI は Razor (ASP.NET MVC の UI 言語) ベース

今回新たにリリースされたのは、Blazor WebAssembly 3.2.0 (GA) です。

近い将来この Blazor が拡張され、ネイティブ アプリケーション (Web アプリケーションでない Windows アプリケーション/Mac アプリ /iOS アプリ/Android アプリ) も作れるようになります。

  • Blazor Server (既存)
    • サーバーサイドを C# で記述。 ASP.NET WebForms に置き換わるものとされる。
    • クライアントサイドとは、SignalR で通信し、リアルタイムに同期をとる。
  • Blazor WebAssembly (今回リリース)
    • Blazor Server と違い、クライアントサイドで C# が動作する Web アプリケーションを作成できる
    • クライアント サイドのプログラムを JavaScript ではなく、C# で記述。
    • クライアント サイド (Web ブラウザー) 上で、WebAssembly の .NET が動作する
  • Blazor PWA (Progressive Web Application) (将来)
    • Web アプリケーションが単独のアプリケーションとして動作する
  • Blazor Hybrid (将来)
    • Electron や WebView を用いてデスクトップアプリケーションを開発
  • Blazor Native (将来)
    • ネイティブアプリケーションを開発
しろまる 参考
くろまる 新たな Windows アプリケーション開発方法

新たな Windows アプリケーション ライブラリーとして WinUI 3 が発表になりました。

  • WinUI 3 Preview 1
    • UWP と Win32 アプリケーションをサポート
    • C/C++、.NET 5、WebView2、Fluent Design Controls に対応

しかく 開発ツール関連

しろまる GitHub Codespaces/Visual Studio Codespaces

以下が発表されました:

  • GitHub Codespaces
  • Visual Studio Codespaces

Web 版 (クラウド版) の Visual Studio Code/Visual Studio です。

Visual Studio Codespaces は、以前 Visual Studio Online と呼ばれていたものです。

ネイティブアプリケーションだった Office が Web 版になり、Microsoft 365 になったように、様々なツールがクラウド版になっていきます。

しろまる Visual Studio
  • Visual Studio 2019 の 16.6 と 16.7 Preview 1 が公開されました。
  • Live Share でボイスチャットがサポートされます。
  • Windows Forms Designer for .NET Core がリリースされました。
  • Surface Duo (2 画面) の開発なども行えるようになってきました。
  • ML.NET 開発用の Model Builder が組み込まれました。
しろまる 参考
しろまる C# 9.0

C# 9.0 が発表されました。

しろまる 参考

しかく Azure 関連

しろまる Azure

Serverless や AI/Data などを中心にアップデートされています。

  • AKS (Azure Kubernetes Service)
  • Windows Server コンテナー
  • Private Link
  • Spot VM
しろまる Data 関連
  • Cosmos DB

Free Tier

AutoScale

Azure Synapse Link: データベース分析サービス

しろまる ML 関連
  • Cognitive Services
    • Personalizer
    • Speech Voice
  • Azure Machine Learning
    • AutoML 周り
    • Responsible ML
    • AI スーパー コンピューターの発表
しろまる 参考

しかく Power Platform/Microsoft 365

しろまる Power Platform

Power Apps や Power Automate、Power BI、Dynamics 365、Microsoft 365 の新たな統合機能の発表

しろまる Microsoft 365 (旧名 : Office 365)

Microsoft Teams の多数のアップデートの予定が発表

しかく Windows 関連

しろまる Terminal

・ Windows Terminal 1.0

次のような機能があります。

Microsoft Store からインストールできます。

  • タブ機能

タブごとに Windows Subsystem for Linux、コマンドプロンプトや PowerShell など

タブの内部をペインに分割する機能

しろまる WSL2

WSL は、Windows に組み込まれた virtual な Linux 環境です。

Microsoft Store からインストールできます。

WSL2 で新たに GPU がサポートされます。 CUDA 利用できたり、GPU 版 Tensorfow が動作できたりします。

しろまる パッケージ マネージャー

winget という Windows Package Manager (Preview 版) がリリースされました。

Linux のようにコマンド ラインから簡単にアプリケーションなどがインストールできます。

参考:Windows Package Manager Preview | Windows Command Line
しろまる API

Project Reunion というプロジェクトが発表されました。

Windows の API は現在次のように 2 つ ありますが、これを統合しようというプロジェクトです。

  • Windows の 2 つの API
    • Win32: 従来の API
    • WinRT: UWP (Universal Windows Platform) 用の API

しかく 関連サイト

]]>
[C#] C#の新機能勉強会 〜C#7、8の新機能を活用して速く安全なプログラムを書こう〜 tag:blog.shos.info,2020://1.935 2020年02月14日T14:59:59Z 2020年02月21日T06:17:24Z 「C#の新機能勉強会 〜C#7、8の新機能を活用して速く安全なプログラムを書こ... Fujiwo http://www.shos.info 「C#の新機能勉強会 〜C#7、8の新機能を活用して速く安全なプログラムを書こう〜」の資料をアップした。

C#7、8 では、struct (値型) 関連の便利な機能追加が多いので、その辺りに注力してみた。

資料

参考資料

]]>
[Event] BuriKaigi 2020 が開催されました tag:blog.shos.info,2020://1.934 2020年02月02日T14:59:59Z 2020年02月21日T06:33:05Z 毎年冬に富山で開催されている BuriKaigi (*)。 今回も、90名もの方... Fujiwo http://www.shos.info 毎年冬に富山で開催されている BuriKaigi (*)。
今回も、90名もの方にご参加いただき、大いに盛り上がりました。

昨年までは2トラックでしたが、今回は3トラックになりました (ルームA, B, C)。
リンクなどをまとめておきます。

(*) BuriKaigi とは何かということは次に詳しく書かれています: Burikaigi という毎年冬のイベント | hikaruworld | Medium

開催概要

BuriKaigi 2020
日時2020年2月1日(土) 13:00〜19:00 (終了後懇親会)
会場富山県民会館 (懇親会会場: 割烹 扇)

イベントの様子

#BuriKaigi #BuriKaigiC https://t.co/rSCc4Nqcea pic.twitter.com/BvdLN5oLKa

— Fujio Kojima (@Fujiwo) February 1, 2020

#BuriKaigi #BuriKaigiC 森さんのジョシュア ツリーのお話。 https://t.co/LO2rNRe5pt pic.twitter.com/oegNAwpRAg

— Fujio Kojima (@Fujiwo) February 1, 2020

#BuriKaigi #BuriKaigiA https://t.co/srTUaBsInF pic.twitter.com/4fpqBZMK7D

— Fujio Kojima (@Fujiwo) February 1, 2020

#BuriKaigi #BuriKaigiA マイクロソフト井上章さんのキーノート。なんと Windows DNA のお話から。 https://t.co/jALoFO3lKy pic.twitter.com/56lVsuXH8m

— Fujio Kojima (@Fujiwo) February 1, 2020

#BuriKaigi #BuriKaigiA 室長さんと杉本さんの Dynamic なセッション。 https://t.co/vmNnjYs6Qz pic.twitter.com/vbn4YDXJtx

— Fujio Kojima (@Fujiwo) February 1, 2020

ブリ会議恒例!
ドキドキライブコーディング!
満員御礼!

#burikaigi pic.twitter.com/VzUQ33vHEP

— Kazuya Sugimoto @CData Software Japan (@sugimomoto) February 1, 2020

ライブコーディング合戦始まった#burikaigi #burikaigiA pic.twitter.com/kueuMIJIoq

— ちゅき[2/8 わんくま大阪ですよー] (@Chuki) February 1, 2020

#burikaigi #burikaigiA
C# ドキドキ ライブ コーディング!!
石野 光仁 氏 @ailight
鈴木 孝明 氏 @xin9le
小島 富治雄 氏 @Fujiwo
室星 亮太 氏 @ryotamurohoshi pic.twitter.com/5sMYfcgop2

— あると沙樹/Studioさきあると (@sakiaruto) February 1, 2020

ドキドキライブコーディング楽しい!#burikaigi #burikaigiA pic.twitter.com/9EgBOYB4Pj

— jun@Jun-nyan(sɹǝunɾ) (@juners) February 1, 2020

まさかの写真入れ替えに対してCPU負荷で小島さんが逆転!#burikaigi #burikaigiA pic.twitter.com/PKTkRdn6l3

— jun@Jun-nyan(sɹǝunɾ) (@juners) February 1, 2020

#burikaigi 石野さん(@AILight )たちによる「C# ドキドキ ライブ コーディング!!」。後半は4名の方々が事前に作ってきたプログラムによるスピード対決です(゚∀゚)
みんなしてチートしてておもろいwww pic.twitter.com/fBfOKF1nWX

— オーニシ@2/15富山IT勉強会Zabbix入門 (@onishi_feuer) February 1, 2020

スライド写真多めですが、勉強会編もアップします(ほぼ未選別)
#burikaigi
2020年02月01日 Burikaigi2020 勉強会編https://t.co/D7m394hKGR

— jun@Jun-nyan(sɹǝunɾ) (@juners) February 2, 2020

アップロード終わったのでまずは 懇親会の写真をアルバムで上げます。 #burikaigi
2020年02月01日 Burikaigi2020 懇親会編https://t.co/p7TWVCnYds

— jun@Jun-nyan(sɹǝunɾ) (@juners) February 2, 2020

#BuriKaigi 懇親会の様子。 https://t.co/bMwt6cpmw0 pic.twitter.com/wJ3ETkK0Ln

— Fujio Kojima (@Fujiwo) February 4, 2020

ブリしゃぶの準備#burikaigi pic.twitter.com/8ftFGcZIfv

— なぎせ ゆうき (@nagise) February 1, 2020

これは良い幻想的#BuriKaigi pic.twitter.com/ZqeKexvxzK

— りなたむ MVP 🇯🇵 / Ryota / #PowerAddict (@R_t_A_n_M) February 1, 2020

#BuriKaigi https://t.co/NLyWTsezf7 pic.twitter.com/CeNsOh4wjx

— Fujio Kojima (@Fujiwo) February 1, 2020

資料

ルームA
ルームB
ルームC
LT

写真・ビデオ

ブログ

]]>
<![cdata[新たな Web アプリケーションフレームワーク「Blazor」 ‐ ネイティブ アプリケーション開発も可能に]]> tag:blog.shos.info,2020://1.933 2020年01月16日T14:59:59Z 2020年02月21日T06:35:48Z 日本時間で昨日、「.NET Conf: Focus on Blazor」という... Fujiwo http://www.shos.info 日本時間で昨日、「.NET Conf: Focus on Blazor」というオンライン カンファレンスが開催され、Blazor に関する新たな発表がなされた。
現在、セッション動画を観ることができる。

Blazor は、C#/.NET で Web アプリケーションを開発できるプラットフォームとして、.NET Core 3 で正式リリースされた。
従来の ASP.NET ではサーバーサイドを C#/.NET、クライアントサイドを JavaScript (や TypeScript) で記述していたが、Blazor ではサーバーサイドとクライアントサイドを統一した言語 (C#) で記述できるのが大きなメリットだ。これにより、単一のコードでモデルが記述できるようになる。

今回、Blazor に関して、以下のように多くの新技術が発表になった:

  • Blazor Server (以前発表済み)
    • .NET Core 3 で正式版
    • Web アプリケーション (SPA: Single Page Application) 用
    • サーバーサイドでC#/.NETのコードが動作
    • クライアントサイドも JavaScript でなく C# で記述
  • Blazor WebAssembly
    • 2020年5月に正式版の予定
    • Web アプリケーション (SPA: Single Page Application) 用
    • クライアントサイドでC#/.NETのコードが動作
    • クライアントサイドも JavaScript でなく C# で記述
  • Blazor PWA
    • 正式版は未定
    • PWA (Progressive Web Apps: デスクトップ アプリケーションのように動作するWeb アプリケーション) 用
  • Blazor Hybrid
    • 正式版は未定
    • Electron や WebView を使った HTML ベースのデスクトップ アプリケーション用
  • Blazor Native
    • 正式版は未定
    • HTML を使わないデスクトップ アプリケーション用
  • Mobile Blazor Bindings
    • 正式版は未定
    • Blazor のコードから iOS や Android の機能を呼び出せるようにする仕組み
    • これにより Blazor で iOS や Android のネイティブ アプリケーションを開発できる

参考資料

]]>
<![cdata[[typescript][webgl][three.js] Boids (an artificial life program) —shoal simulator written in TypeScript—]]> tag:blog.shos.info,2019://1.932 2019年11月02日T14:59:59Z 2019年11月02日T00:35:37Z Boids とは Boids は、Craig Reynolds 氏によって作ら... Fujiwo http://www.shos.info Boids とは Boids は、Craig Reynolds 氏によって作られた人工生命のシミュレーションだ。 Boid の名は、「Bird (鳥) oid (もどき)」から来ており、元は鳥の群れの動きを真似ている。

それぞれの個体を次に上げる 3 つの規則にしたがって動かすというだけで、群れのような動きを実現している:

Boids の 3 つの規則
分離 (Separation): 近くの仲間にぶつからない方向に移動
分離 (Separation)
分離 (Separation)
整列 (Alignment): 近くの仲間が平均的に向かっている方に向かう
整列 (Alignment)
[画像:整列 (Alignment)]
集結 (Cohesion): 近くの仲間の中心方向に移動する
集結 (Cohesion)
[画像:集結 (Cohesion)]

参考ページ

デモ

TypeScript などで Boids のデモを 3 種類作成してみた。

鳥の群れではなく、魚の群れを意識した。

(注記) 各画像をクリックするとそれぞれのページへ飛ぶ

2D版: Boids (an artificial life program) —shoal simulator written in TypeScript
Boids (an artificial life program) —shoal simulator written in TypeScript
3D版: Boids (an artificial life program) 3D —shoal simulator written in TypeScript with Three.js—
Boids (an artificial life program) 3D —shoal simulator written in TypeScript with Three.js—
3D 裸眼立体視版: Boids (an artificial life program) 3D (Cross-eyed/Parallel Free-viewing Stereoscopy) —shoal simulator written in TypeScript with Three.js—
Boids (an artificial life program) 3D (Cross-eyed/Parallel Free-viewing Stereoscopy) —shoal simulator written in TypeScript with Three.js—

2D版では2次元ベクトル、3D版では3次元ベクトルで、個体の位置や速度を計算している。

2つの3D版は、Three.js というライブラリーを使って WebGL で動かしている。

参考:

3D 裸眼立体視版は、裸眼立体視 (交差法または平行法) ができる人向けだ。 立体視の方法については、次のページなどが参考になる。

参考:

なお、各版ともパラメーターを色々と変更できるので試してほしい。

これらのデモ ページの実装については、ソースコードを参照してほしい。

ソースコード

ソースコードは、GitHub に上げた:

開発環境/言語/ライブラリー

以下を使って作った:

Visual Studio Code

上記デモは、Visual Studio Code 上で作成した。

Visual Studio Code は、プログラミングに最適な Microsoft 製のテキスト エディターで、Windows 版、macOS 版、Linux 版がある。

HTML や CSS はもちろんのこと、JavaScript や TypeScript、C# などの多種多様なプログラミング言語にも対応している。

Git クライアント、ビルド、シンタックス ハイライト、リファクタリング、インテリセンスなどの機能を持ち、とても使いやすいのでお薦めだ。

どのような機能や言語が使えるかは、Extensions for Visual Studio family of products | Visual Studio Marketplace が参考になる。

参考:

TypeScript

TypeScript は、設定を変えることにより、"ES3"、"ES5"、"ES2015"、"ES2016"、"ES2017"、"ES2018"、"ES2019" にコンパイルすることができる。

デモでは、"ES5" を使っている。

TypeScript のコンパイル オプションは、"tsconfig.json"というファイルで行う。 今回は次のような内容とした。

tsconfig.json


{
 "compilerOptions": {
 /* Basic Options */
 "target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
 "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
 "sourceMap": true, /* Generates corresponding '.map' file. */
 /* Strict Type-Checking Options */
 "strict": true, /* Enable all strict type-checking options. */
 /* Module Resolution Options */
 "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
 }
}

TypeScript は、Visual Studio Code から簡単に JavaScript にコンパイルできる。

Visual Studio Code でのコンパイル
[画像:Visual Studio Code でのコンパイル]

ちなみに、次のような TypeScript の場合:

class Vector3D {
 x: number;
 y: number;
 z: number;
 get absoluteValue(): number {
 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
 }
 constructor(x: number = 0, y: number = 0, z: number = 0) {
 this.x = x;
 this.y = y;
 this.z = z;
 }
 clone(): Vector3D {
 return new Vector3D(this.x, this.y, this.z);
 }
 plus(another: Vector3D): Vector3D {
 return new Vector3D(this.x + another.x, this.y + another.y, this.z + another.z);
 }
 plusEqual(another: Vector3D): void {
 this.x += another.x;
 this.y += another.y;
 this.z += another.z;
 }
 minus(another: Vector3D): Vector3D {
 return new Vector3D(this.x - another.x, this.y - another.y, this.z - another.z);
 }
 minusEqual(another: Vector3D): void {
 this.x -= another.x;
 this.y -= another.y;
 this.z -= another.z;
 }
 multiply(value: number): Vector3D {
 return new Vector3D(this.x * value, this.y * value, this.z * value);
 }
 innerProduct(another: Vector3D): Vector3D {
 return new Vector3D(this.x * another.x, this.y * another.y, this.z * another.z);
 }
 divideBy(value: number): Vector3D {
 return new Vector3D(this.x / value, this.y / value, this.z / value);
 }
 divideByEqual(value: number): void {
 this.x /= value;
 this.y /= value;
 this.z /= value;
 }
 getDistance(another: Vector3D): number {
 return this.minus(another).absoluteValue;
 }
}

"ES5" でコンパイルしてできた JavaScript はこんな感じ:

"use strict";
var Vector3D = /** @class */ (function () {
 function Vector3D(x, y, z) {
 if (x === void 0) { x = 0; }
 if (y === void 0) { y = 0; }
 if (z === void 0) { z = 0; }
 this.x = x;
 this.y = y;
 this.z = z;
 }
 Object.defineProperty(Vector3D.prototype, "absoluteValue", {
 get: function () {
 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
 },
 enumerable: true,
 configurable: true
 });
 Vector3D.prototype.clone = function () {
 return new Vector3D(this.x, this.y, this.z);
 };
 Vector3D.prototype.plus = function (another) {
 return new Vector3D(this.x + another.x, this.y + another.y, this.z + another.z);
 };
 Vector3D.prototype.plusEqual = function (another) {
 this.x += another.x;
 this.y += another.y;
 this.z += another.z;
 };
 Vector3D.prototype.minus = function (another) {
 return new Vector3D(this.x - another.x, this.y - another.y, this.z - another.z);
 };
 Vector3D.prototype.minusEqual = function (another) {
 this.x -= another.x;
 this.y -= another.y;
 this.z -= another.z;
 };
 Vector3D.prototype.multiply = function (value) {
 return new Vector3D(this.x * value, this.y * value, this.z * value);
 };
 Vector3D.prototype.innerProduct = function (another) {
 return new Vector3D(this.x * another.x, this.y * another.y, this.z * another.z);
 };
 Vector3D.prototype.divideBy = function (value) {
 return new Vector3D(this.x / value, this.y / value, this.z / value);
 };
 Vector3D.prototype.divideByEqual = function (value) {
 this.x /= value;
 this.y /= value;
 this.z /= value;
 };
 Vector3D.prototype.getDistance = function (another) {
 return this.minus(another).absoluteValue;
 };
 return Vector3D;
}());

class がないので、prototype と function での実装だ。

一方、"ES2019" でコンパイルしてできた JavaScript はこんな感じ:

"use strict";
class Vector3D {
 constructor(x = 0, y = 0, z = 0) {
 this.x = x;
 this.y = y;
 this.z = z;
 }
 get absoluteValue() {
 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
 }
 clone() {
 return new Vector3D(this.x, this.y, this.z);
 }
 plus(another) {
 return new Vector3D(this.x + another.x, this.y + another.y, this.z + another.z);
 }
 plusEqual(another) {
 this.x += another.x;
 this.y += another.y;
 this.z += another.z;
 }
 minus(another) {
 return new Vector3D(this.x - another.x, this.y - another.y, this.z - another.z);
 }
 minusEqual(another) {
 this.x -= another.x;
 this.y -= another.y;
 this.z -= another.z;
 }
 multiply(value) {
 return new Vector3D(this.x * value, this.y * value, this.z * value);
 }
 innerProduct(another) {
 return new Vector3D(this.x * another.x, this.y * another.y, this.z * another.z);
 }
 divideBy(value) {
 return new Vector3D(this.x / value, this.y / value, this.z / value);
 }
 divideByEqual(value) {
 this.x /= value;
 this.y /= value;
 this.z /= value;
 }
 getDistance(another) {
 return this.minus(another).absoluteValue;
 }
}

こちらは class があるので TypeScript のコードとあまり変わらない。"ES5" とは、まるで別の言語のように見えるのが面白い。

]]>
[C#][.NET] Shos.CsvHelper (simple library for reading and writing CSV) tag:blog.shos.info,2019://1.931 2019年10月16日T14:59:59Z 2020年01月22日T08:15:15Z Click here for Japanese version (日本語版はこ... Fujiwo http://www.shos.info
  • Click here for Japanese version (日本語版はこちら)
  • I wrote a simple library for reading and writing CSV (the Values Comma-Separated or Character-Separated Values).

    The csv format file is sometimes necessary because it can be displayed / edited with Excel and is simple. There are other libraries that read and write csv already, but I tried to make it simpler.

    With this library, you can read and write plain object collections (IEnumerable<Something>) in csv format.

    How to use

    Overview of how to use

    First, prepare something IEnumerable<TElement>:

     An IEnumerable<TElement> something
     IEnumerable<ToDo> toDoes = new ToDoList();
    

    For example this class:

     class ToDoList : IEnumerable<ToDo> // sample collection
     {
     public IEnumerator<ToDo> GetEnumerator()
     {
     yield return new ToDo { Id = 1, Title = "filing tax returns", Deadline = new DateTime(2018, 12, 1) };
     yield return new ToDo { Id = 2, Title = "report of a business trip", Detail = "\"ASAP\"", DaySpan = new DaySpan(3), Priority = Priority.High };
     yield return new ToDo { Id = 3, Title = "expense slips", Detail = "book expenses: \"C# 6.0 and the .NET 4.6 Framework\",\"The C# Programming\"", Priority = Priority.Low, Done = true };
     yield return new ToDo { Id = 4, Title = " wish list ", Detail = " \t (1) \"milk\"\n \t (2) shampoo\n \t (3) tissue ", Priority = Priority.High };
     }
     IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
     }
    

    You can write this as:

     const string csvFileName = "todo.csv";
     await toDoes.WriteCsvAsync(csvFileName);
    

    The resulting csv file looks like this:

    • If the value contains commas, delimiters, newlines, or double quotes, these are enclosed in double quotes.
    • Double quotations in the value are replaced by two double quotations.
    Id,Title,Deadline,Done,Priority,Details,DaySpan
    1,filing tax returns,2018/12/01 0:00:00,False,Middle,,0
    2,report of a business trip,2017/07/12 13:13:01,False,High,"""ASAP""",3
    3,expense slips,2017/07/12 13:13:01,True,Low,"book expenses: ""C# 6.0 and the .NET 4.6 Framework"",""The C# Programming""",0
    4, wish list ,2017/07/12 13:13:01,False,High," 	 (1) ""milk""
     	 (2) shampoo
     	 (3) tissue ",0
    

    Open the created csv file in Excel
    [画像:Open the created csv file in Excel]

    You also can read a csv file like this:

     IEnumerable<ToDo> newToDoes = await CsvSerializer.ReadCsvAsync<ToDo>(csvFileName);
    

    Things to read and write

    Public properties with both "get" and "set" of each element in the collection are read and written to csv files.

    When writing:

    When writing, it is converted to a string with the "ToString()" method regardless of the type.

    When reading:

    When reading, the string type is left as is, and enum (enumeration type) is read as the value of the string. For other types, it tries to change the string to a value using "TryParse" or "Parse". Types that cannot do either of these will not be read.

    Properties that have both "get" and "set" and are of one of the following types are read:

    • String type
    • enum
    • A type that has a default constructor and can be "TryParse" or "Parse" (Basic numeric types such as int, DateTime, user-defined types with "TryParse" or "Parse")
    Other rules
    • Properties with the [CsvIgnore ()] attribute are not read or written.
    • Properties with the [ColumnName("Column name")] attribute will be changed to the one with the specified column name in the csv file.

    For example, the above ToDo class is like this:

     // Sample element type
     // Properties marked with ✔ will be read / written
     // Properties marked with ✖ won't be read / written
     class ToDo
     {
     public int Id { get; set; } // ✔
     public string Title { get; set; } = ""; // ✔
     public DateTime Deadline { get; set; } = DateTime.Now; // ✔
     public bool Done { get; set; } // ✔
     public Priority Priority { get; set; } = Priority.Middle; // ✔ user-defined enum 
     [ColumnName("Details")]
     public string Detail { get; set; } = ""; // ✔ [ColumnName ("Details")] changes the column name in the csv file to "Details"
     public DaySpan DaySpan { get; set; } // ✔ User-defined type with "Parse" (without "TryParse")
     [CsvIgnore()]
     public string Option { get; set; } = ""; // ✖ Ignored because [CsvIgnore()] is attached
     public string Version => "1.0"; // ✖ Ignored because it is only a get property
     }
    

    The user-defined types used in the above ToDo class are as follows:

     // User-defined enum example
     enum Priority { High, Middle, Low }
     // Example of a user-defined type with "Parse" (without "TryParse")
     struct DaySpan
     {
     public int Value { get; private set; }
     public DaySpan(int value) => Value = value;
     public static DaySpan Parse(string text) => new DaySpan(int.Parse(text));
     public override string ToString() => Value.ToString();
     }
    

    With or without header

    csv can be read and written even if it has no header part (eg the first line of the csv file above).

    However, if there is a header part, it can be read by collating the header part even if the column is switched, but if there is no header part, it cannot be read if the column is switched.

    Example of writing without a header:

     await toDoes.WriteCsvAsync(csvFilePathName: csvFileName, hasHeader: false);
    

    Csv file created:

    1,filing tax returns,2018/12/01 0:00:00,False,Middle,,0
    2,report of a business trip,2017/07/06 18:08:13,False,High,"""ASAP""",3
    3,expense slips,2017/07/06 18:08:13,True,Low,"book expenses: ""C# 6.0 and the .NET 4.6 Framework"",""The C# Programming""",0
    4, wish list ,2017/07/12 13:13:01,False,High," 	 (1) ""milk""
     	 (2) shampoo
     	 (3) tissue ",0

    Open the created csv file in Excel
    [画像:Open the created csv file in Excel]

    To read a csv file without a header:

     IEnumerable<ToDo> newToDoes = await CsvSerializer.ReadCsvAsync<ToDo>(csvFilePathName: csvFileName, hasHeader: false); 

    Other specification methods

    The character code can be changed (default is UTF8).

     CsvSerializer.Encoding = Encoding.GetEncoding(0);
    

    The delimiter can also be changed (default is ',').

     CsvSerializer.Separator = '\t';
    

    You can also use stream instead of file name.

     using (var stream = new FileStream(csvFileName, FileMode.Create))
     await collection.WriteCsvAsync(stream);
    

    You can leave the stream open after reading or writing by specifying leaveOpen.

     using (var stream = new FileStream(csvFileName, FileMode.Create))
     await collection.WriteCsvAsync(stream: stream, bufferSize: 1024, leaveOpen:true, hasHeader: true);
    

    In addition to asynchronous methods, there are also synchronous methods.

     toDoes.WriteCsv(csvFileName);
    

    NuGet and GitHub

    These libraries are open to NuGet and can be installed from Visual Studio.

    Source code is available at:

    The projects included are:

    Shos.CsvHelper

    • CSV library
    • .NET Standard Library version
    • You can build a.NET Standard 1.3 and later
    • .NET Network 4.6 or higher, or.NET Core 1.1 or later for
    • NuGet packages that can be installed: NuGet Gallery | Shos.CsvHelper

    Shos.CsvHelper.NetFramework

    Shos.CsvHelperSample.NetCore

    • .NET Core Console applications that use the Shos.CsvHelper sample

    Shos.CsvHelperSample.NetFramework

    • Using Shos.CsvHelper.NetFramework.NET Framework console application sample
    ]]>
    最新の C#/.NET を使用するには (2019年09月25日版) tag:blog.shos.info,2019://1.930 2019年09月24日T14:59:59Z 2019年09月27日T00:17:25Z (注記) 「.NET Core 3.0 正式版リリース」の続き。 先日... Fujiwo http://www.shos.info (注記).NET Core 3.0 正式版リリース」の続き。

    先日 .NET Core 3.0 が正式にリリースされ、C# 8.0 が使えるようになった。
    一方で、.NET Framework の最新版は 4.8 だ (2019年09月25日 現在)。

    現時点での、最新版の .NET を使用する方法をまとめてみよう。

    .NET Framework 4.8 を使うには

    下記からインストール。
    (注記) Developer pack と Language pack の両方

    .NET Core 3 で開発するには

    Visual Studio Installer で Visual Studio 2019 Ver.16.3 以上にバージョンアップ

    Blazor WebAssembly (クライアントサイド Blazor: プレビュー版) を試すには

    最新版の Visual Studio に Blazor テンプレートのインストールが必要
    次を参照

    C# 8.0 で開発するには

    プロジェクト ファイル (*.csproj など) に <LangVersion>8.0</LangVersion> を記述
    (null 許容参照型も有効にするには <Nullable>enable</Nullable> も記述)

    例.

     <?xml version="1.0" encoding="utf-8"?>
     <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     ...
     <PropertyGroup>
     ...
     <LangVersion>8.0</LangVersion>
     <Nullable>enable</Nullable>
     ...
     

    (注記) .NET Core 3.0 アプリケーションのデフォルトの C# のバージョンは 8.0

    参考資料

    ]]>
    .NET Core 3.0 正式版リリース tag:blog.shos.info,2019://1.929 2019年09月23日T22:00:00Z 2019年09月24日T08:11:11Z .NET Core 3.0 正式版リリース 昨日 (2... Fujiwo http://www.shos.info .NET Core 3.0 正式版リリース

    昨日 (2019年09月23日)、.NET Core 3.0 正式版がリリースされた。

    現在これに関連して、.NET Conf 2019 というオンライン カンファレンスが開催されている。
    一部は、YouTube で見ることができる。

    .NET Core 3.0

    Microsoft 製の新たな .NET である .NET Core だが、.NET Core 3.0 では、Windows デスクトップ アプリケーション (Windows Forms と WPF) がサポートされた。

    .NET Core 3.0 のためのソフトウェアの開発には、現在 Visual Studio 2019 の最新版である Ver.16.3.0 が必要だ。
    Visual Studio Installer からアップデートできる。

    但し、現在 .NET Core の Windows Forms のデザイナーには未対応であるようだ。

    (なお .NET Core は、最初の .NET である .NET Framework に比べて様々な最適化がなされているため、より高パフォーマンスとなっている)

    .NET Core の Roadmap

    • 2019/11 .NET Core 3.1 (LTS : Long Term Support 版)
    • 2020/11 .NET 5

    .NET 5 は、.NET Core 3 の次期バージョンだ。

    現在 3つある Microsoft の .NET (.NET Framework, .NET Core, Xamarin) が 1 つに統合される予定。
    これ以降、.NET Framework は保守のみとなり、新機能は追加されなくなる。

    .NET Core 上の C++/CLI

    C++/CLI は .NET Core 3.1 でサポートされる予定だ。

    Blazor

    新たな ASP.NET (.NET での Web アプリケーション プラットフォーム) のフレームワークである Blazor だが、サーバーサイドの Blazor は、既に .NET Core 3.0 でサポートされている。

    サーバーサイドの Blazor は、C# と Razor 構文でコーディングでき、クライアント サイドとの同期はフレームワークによって行われる (内部的には JavaScript を用いて SignalR で通信) という技術だ。

    クライアント サイド Blazor (Blazor WebAssembly) は、WebAssembly で .NET が動作し、C# のアプリケーションがクライアント サイドの Web ブラウザ上で動作するというユニークなものだが、こちらは、現在まだ Preview 版。
    2020年5月のリリースが予定されている。

    C#

    C#8.0 がリリースされた。
    null 許容参照型や非同期ストリームなどがサポートされる。
    非同期ストリームでは、非同期型の IEnumerable である IAsyncEnumerable が使われる。

    関連記事

    ]]>
    Microsoft MVP を再受賞しました (My 15th MVP Award from Microsoft) tag:blog.shos.info,2019://1.928 2019年07月02日T03:00:00Z 2019年07月02日T10:24:15Z Microsoft MVP Award を再受賞しました。15年目になります。... Fujiwo http://www.shos.info MVP_Logo_Horizontal_Preferred_Cyan300_CMYK_72ppi.png

    Microsoft MVP Award を再受賞しました。15年目になります。

    My MVP Profile

    • Microsoft MVP for Development Tools - Visual C# (Jul. 2005 - Dec. 2014)
    • Microsoft MVP for .NET (Jan. 2015 - Oct. 2015)
    • Microsoft MVP for Visual Studio and Development Technologies (Nov. 2015 - Jun. 2018)
    • Microsoft MVP for Developer Technologies (Jul. 2018 - Jun. 2020)

    いい歳の大人をこうして褒めてくれるマイクロソフトに感謝です。

    Microsoft MVP となって、多くの素敵なITエンジニアの皆様との交流の機会が増えました。 皆様いつもありがとうございます。

    ]]>
    [Event] de:code 2019 で C# ドキドキ・ライブコーディング対決をやってきました tag:blog.shos.info,2019://1.927 2019年06月11日T14:59:59Z 2019年06月17日T09:07:00Z 「[Event] C# ドキドキ・ライブコーディング対決 @ de:code... Fujiwo http://www.shos.info
  • 「[Event] C# ドキドキ・ライブコーディング対決 @ de:code」の続き
  • [画像:MW51 | C# ドキドキ・ライブコーディング対決 @ de:code]

    毎年恒例の BuriKaigi などで4人でやっている C# ライブ コーディングセッションを Microsoft の de:code 2019 でやってきました。

    #decode19 のドキドキ・ライブコーディングに来ていただきありがとうございました #MW51

    準備はドキドキというかビクビクで、本場中も内心ヒヤヒヤだったのですが、楽しんでいただけたようでとても嬉しいです!

    大舞台に連れてきてくださった大先輩方、そしてチャックさんありがとうございました。 pic.twitter.com/rib8sRT9r8

    — むろほし (@RyotaMurohoshi) May 30, 2019

    いつもお世話になっているマイクロソフトの井上章 (@chack411) さんのお誘いで実現したものです。 おかげさまでとても素敵な体験になりました。 もちろん、毎回楽しい企画をしてくださる石野 (@AILight) さん、一緒に解答者として登壇した鈴木 (@xin9le) さん、室星 (@RyotaMurohoshi) さん、にも感謝です。

    今回は、Blazor を使用したプログラミングがお題で、次の2つをやりました:

    1. C# ライブ コーディング: その場で出たお題「C# で令和表示」を C#/Blazor で
    2. 七並べプログラム対決: 予め用意した「七並べのAI」を当日マージして対戦

    「七並べ」対決の私の作戦は次の通りです:

    [フレーム]

    99名の皆様が聴きにきてくださり、大変に盛り上がってくださいました。 本当にありがとうございました!

    「MW51 | C# ドキドキ・ライブコーディング対決 @ de:code」 関連記事

    当日の盛り上がりの様子の一部は、以下のリンクで読むことができます。

    de:code 2019 関連記事

    de:code 2019 の動画や資料などはこちらから。 (ただし、我々のセッションのものはありません)

    NSAT

    アンケート結果の NSAT (Net Satisfaction) がとても良かったので、メモ。
    NSAT
    講師198
    コンテンツ193
    全体195

    参考: NSAT の求め方
    • Positive の比率 (パーセンテージ) = P
      • 4段階評価、5段階評価の場合: 1番上の評価をした人の比率
      • 10段階評価の場合: 1番上と上から2番目の評価の比率の合計
    • Negative の比率 (パーセンテージ) = N
      • 4段階評価の場合: 下2つの合計
      • 5段階評価の場合: 下3つの合計
      • 10段階評価の場合: 下4つの合計
    • NSAT = P - N + 100 (200点満点、平均100点)
    ]]>
    Microsoft Build 2019 リンク集 (2019年05月07日) tag:blog.shos.info,2019://1.926 2019年05月07日T14:59:59Z 2019年05月07日T08:52:44Z 全般 Microsoft Build 2019 Announcements | ... Fujiwo http://www.shos.info 全般

    一日目

    全般

    Azure

    Office 365

    .NET

    ML

    Visual Studio

    Windows Terminal

    Windows の Linux

    その他

    ]]>
    [Event] C# ドキドキ・ライブコーディング対決 @ de:code tag:blog.shos.info,2019://1.925 2019年04月15日T14:59:59Z 2019年04月16日T00:22:28Z 毎年恒例の BuriKaigi などで4人でやっている C# ライブ コーデ... Fujiwo http://www.shos.info MW51 | C# ドキドキ・ライブコーディング対決 @ de:code

    毎年恒例の BuriKaigi などで4人でやっている C# ライブ コーディングセッションを Microsoft の de:code 2019 でやります。

    ]]>
    [Event] 「Global AI Nights in FUKUI」を開催しました tag:blog.shos.info,2019://1.924 2019年04月02日T14:59:59Z 2019年04月03日T03:12:52Z (注記) [Event] 「Global AI Nights in FUKUI」 (... Fujiwo http://www.shos.info Global AI Nights in FUKUI

    (注記) [Event] 「Global AI Nights in FUKUI」 (2019年4月2日) を開催しますの続き。

    Global AI Nights とは

    世界の47会場で、Global AI Nights が開催されています。

    日本では、下記3会場で開催されました。

    福井会場にも AI に関心の深い参加者が集まり、おおいに盛り上がりました。

    キーノート「Global AI Night Keynote April 2019」 (英語)

    [フレーム]

    当日の様子

    View this post on Instagram

    #GlobalAINight #fukui 会場の福井県産業情報センター。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    View this post on Instagram

    #GlobalAINight #fukui スタッフ用のパーカーとTシャツ。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    大盛況#GlobalAINight #fukui pic.twitter.com/VSwPBK2bj2

    — 福坂 (@fukusaka291) April 2, 2019
    View this post on Instagram

    #GlobalAINight #fukui 始まり。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    #GlobalAINight #fukui 部屋は満席! pic.twitter.com/P03JEA8ZXr

    — jun1s (@jun1s) April 2, 2019

    Seeing AIのデモ。機械が目の代わりになる。#GlobalAINight #fukui pic.twitter.com/w0E9wdLoL2

    — jun1s (@jun1s) April 2, 2019
    View this post on Instagram

    #GlobalAINight #fukui

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    View this post on Instagram

    #GlobalAINight #fukui 機械学習基礎編。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    ディープラーニングの概念おさらい! 続きを聞きたい方、まだ今からでも、産業情報センター7Fへどうぞ! #GlobalAINight #fukui pic.twitter.com/ieF6EzPnlp

    — jun1s (@jun1s) April 2, 2019
    View this post on Instagram

    #GlobalAINight #fukui ニューラル ネットワークとは。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    #GlobalAINight #fukui 「AI流行ってるから」なんて不純な動機では成功しない! pic.twitter.com/llNWg2TTMX

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui Face APIを使って顧客に合わせたターゲティング販売戦略の提案。店の前を歩く人の中でどんな人が来店するのか。レイアウトの変更に対する効果測定、などなど...。こういうのどんどん利用していった方が良いんでしょうね。Microsoftのサイトから利用可能。 pic.twitter.com/bgfHv6CVO6

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui 画像の分析APIの紹介。Microsoftのサイトから利用できるし、もちろんプログラムコードから呼び出せる。 pic.twitter.com/GtD1NbSrr5

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui 画像分析APIを呼び出すコードの紹介とデモ。面白〜い! pic.twitter.com/chO7jLeG9K

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui Custom Vision APIを使うと、簡単に機械学習をさせたモデルを作る事ができる。作成したモデルを自分のプログラム(Microsoft MLやiOS、モバイルなど)で使う事もできる。これは面白そう。犬や猫などの画像を与えて、犬か猫かを判別させるモデルを作成するデモも面白かった! pic.twitter.com/thtYab3ZhF

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui 福井コンピュータの過去のすべての株価変動を機械学習させるデモ。過去二週間の株価変動から、次に上がるか下がるかをAIに予想させ、その結果を繰り返し学習させていく。その結果、「次に株価が上がるかどうか」予想的中率50%のAIが出来上がりましたw 株価予想って難しいw pic.twitter.com/8zuFs1xug0

    — jun1s (@jun1s) April 2, 2019

    #GlobalAINight #fukui Microsoft Azure Machine Learning Studioのデモ。株価予測をさせてみる。なんとノンプログラミングで機械学習モデルを作成できる。出来上がったモデルは、ウェブ上にAPIとして公開でき、自分のプラグラムから呼び出せるようになる。こりゃ面白い! pic.twitter.com/8iJQWVJQce

    — jun1s (@jun1s) April 2, 2019
    View this post on Instagram

    #GlobalAINight #fukui 終了。

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    View this post on Instagram

    #GlobalAINight #fukui Q&A.

    Fujio Kojimaさん(@fujiwo)がシェアした投稿 -

    #GlobalAINight #fukui 終了! めっちゃ面白かったー! 参加して良かった...! 機械学習面白い。ちなみに、参加者にはサブウェイの無料クーポンが配られるらしいのですが、福井はサブウェイありませんと言ったらこのお菓子が配布されることになったそうです。サブウェイがない地域だってあるんです...w pic.twitter.com/80OcPSOmqm

    — jun1s (@jun1s) April 2, 2019

    資料

    [フレーム]
    『機械学習 (AI/ML) の基礎と Microsoft の AI | 2019年04月02日 Global AI Nights Fukui from Fujio Kojima
    ]]>

    AltStyle によって変換されたページ (->オリジナル) /