<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>takanostのブログ</title>
<link>https://ameblo.jp/takanost/</link>
<atom:link href="https://rssblog.ameba.jp/takanost/rss20.xml" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
<description>定年退職した元プログラマーがC#を勉強しています</description>
<language>ja</language>
<item>
<title>php で メール送信する</title>
<description>
<![CDATA[ <p>Windows xampp で smtp4dev を使っています。</p><h4>php.ini の設定</h4><p>[mail function]<br>; For Win32 only.<br>; http://php.net/smtp<br>;SMTP = localhost<br>; http://php.net/smtp-port<br>;smtp_port = 25<br><br>; For Win32 only.<br>; http://php.net/sendmail-from<br>;sendmail_from = me@example.com<br><br>; For Unix only. &nbsp;You may supply arguments as well (default: "sendmail -t -i").<br>; http://php.net/sendmail-path<br>sendmail_path = "\"C:\pleiades\2022-09\xampp\sendmail\sendmail.exe\" -t -i"</p><h4>sendmail.iniの設定</h4><div>[sendmail]<br><br>; you must change mail.mydomain.com to your smtp server,<br>; or to IIS's "pickup" directory. &nbsp;(generally C:\Inetpub\mailroot\Pickup)<br>; emails delivered via IIS's pickup directory cause sendmail to<br>; run quicker, but you won't get error messages back to the calling<br>; application.<br><br>;smtp_server=mail.mydomain.com<br>smtp_server=localhost<br><br>; smtp port (normally 25)<br><br>smtp_port=25<br><br>; SMTPS (SSL) support<br>; &nbsp; auto = use SSL for port 465, otherwise try to use TLS<br>; &nbsp; ssl &nbsp;= alway use SSL<br>; &nbsp; tls &nbsp;= always use TLS<br>; &nbsp; none = never try to use SSL<br><br>smtp_ssl=auto<br>&nbsp;</div><h4>&nbsp;</h4><div>&nbsp;</div>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12775252534.html</link>
<pubDate>Sat, 19 Nov 2022 11:44:54 +0900</pubDate>
</item>
<item>
<title>C# 拡張関数</title>
<description>
<![CDATA[ <p>引数にthisを付けることによって、あたかもstring型の関数のように振る舞う。</p><div style="line-height:95%"><blockquote><p>using System;</p><p>&nbsp;</p><p>public static class StringShow<br>{<br>&nbsp; &nbsp; public static void Show(<span style="background-color:#ffcc00;">this</span> string str)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(str);<br>&nbsp; &nbsp; }<br>}<br>class Program<br>{<br>&nbsp; &nbsp; static void Main()<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; "Hello World!".Show();<br>&nbsp; &nbsp; }<br>}</p></blockquote></div>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12669700444.html</link>
<pubDate>Tue, 20 Apr 2021 17:59:49 +0900</pubDate>
</item>
<item>
<title>C# インターフェースメンバの明示的な実装</title>
<description>
<![CDATA[ <p>インターフェースに定義されている関数は実装するとpublicとなる。これを避けたい場合、明示的インターフェースメンバという方法がある。</p><p>&nbsp;</p><div style="line-height:95%"><blockquote><p>using System;</p><p>interface IBase<br>{<br>&nbsp; &nbsp; int GetNumber();<br>&nbsp; &nbsp;&nbsp;<br>}<br>class Derived:IBase<br>{<br>&nbsp; &nbsp; int <span style="background-color:#ffcc00;">IBase.GetNumber()</span><br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; return 1;<br>&nbsp; &nbsp; }<br>}<br>class Program<br>{<br><br>&nbsp; &nbsp; static void Main()<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; Derived der = new Derived();<br>&nbsp; &nbsp; &nbsp; &nbsp; //Console.WriteLine(der.GetNumber()); // これはコンパイルエラー<br><br>&nbsp; &nbsp; &nbsp; &nbsp; IBase bs = new Derived();<br>&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(bs.GetNumber());<br><br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>}</p></blockquote></div>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12668890345.html</link>
<pubDate>Fri, 16 Apr 2021 14:34:18 +0900</pubDate>
</item>
<item>
<title>C# yield return と yield break の例</title>
<description>
<![CDATA[ <p>yield return を使うと、戻り値が配列で返してくれるような感じになる。</p><p>yield break は yield return を使わない場合の return に相当する。</p><p>&nbsp;</p><div style="line-height:96%"><blockquote><p>using System;</p><p>using System.Collections.Generic;</p><p>class Data<br>{<br>&nbsp; &nbsp; public IEnumerator&lt;int&gt; GetEnumerator()<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; yield return 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; yield return 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; Random r = new Random();<br>&nbsp; &nbsp; &nbsp; &nbsp; int t = r.Next(0, 5);<br>&nbsp; &nbsp; &nbsp; &nbsp; if (t % 2 == 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield break;<br>&nbsp; &nbsp; &nbsp; &nbsp; yield return t;<br>&nbsp; &nbsp; }<br>}<br>class Program<br>{<br>&nbsp; &nbsp; static void Main()<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; foreach (int number in new Data())<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.Write(number.ToString() + " ");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; Console.ReadKey();<br>&nbsp; &nbsp; }<br>}</p></blockquote></div>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12668542664.html</link>
<pubDate>Wed, 14 Apr 2021 18:43:13 +0900</pubDate>
</item>
<item>
<title>.Net4.5(C#５) 非同期 async/await その２</title>
<description>
<![CDATA[ <p><a href="https://ameblo.jp/takanost/entry-12667521655.html">.Net4.5(C#５) 非同期 async/awaitはこちら</a>の続き</p><p><a href="https://stat.ameba.jp/user_images/20210409/18/takanost/5c/28/p/o0485032014923753224.png"><img alt="" height="277" src="https://stat.ameba.jp/user_images/20210409/18/takanost/5c/28/p/o0485032014923753224.png" width="420"></a></p><p>重い処理を行っている関数(同期)に戻り値がある場合</p><div style="line-height:95%"><blockquote><p>&nbsp; &nbsp; &nbsp;&nbsp;<span style="font-size:0.83em;">private <span style="background-color:#ffcc00;">async</span> void button1_Click(object sender, EventArgs e)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "開始";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ms = <span style="background-color:#ffcc00;">await</span> Task.Run(() =&gt; HeavyWork());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = String.Format("{0}ミリ秒", ms);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; private long HeavyWork() //処理に時間のかかる関数を想定<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var st = Stopwatch.StartNew();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重い処理をしていると仮定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return st.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p></blockquote><p><span style="font-size:1em;">重い処理を行う関数(非同期)に戻り値がない場合</span></p><blockquote><p>&nbsp; &nbsp; &nbsp; <span style="font-size:0.83em;">private<span style="background-color:#ffcc00;"> async</span> void button1_Click(object sender, EventArgs e)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "開始";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="background-color:#ffcc00;">await</span> HeavyWork();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "終了";<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; private <span style="background-color:#ffcc00;">async</span> Task HeavyWork() //処理に時間のかかる関数を想定<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="background-color:#ffcc00;">await</span> Task.Run(() =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重い処理をしていると仮定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p>&nbsp;</p></blockquote><p><span style="font-size:1em;">重い処理を行う関数(非同期)に戻り値がある場合</span></p><blockquote><p><span style="font-size:1em;">&nbsp; &nbsp; &nbsp; </span><span style="font-size:0.83em;">private <span style="background-color:#ffcc00;">async</span> void button1_Click(object sender, EventArgs e)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "開始";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ms = <span style="background-color:#ffcc00;">await</span> HeavyWork();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = String.Format("{0}ミリ秒", ms);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; private <span style="background-color:#ffcc00;">async</span> Task&lt;long&gt; HeavyWork() //処理に時間のかかる関数を想定<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var st = Stopwatch.StartNew();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="background-color:#ffcc00;">await</span> Task.Run(() =&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重い処理をしていると仮定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st.Stop();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return st.ElapsedMilliseconds;<br>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p>&nbsp;</p></blockquote></div>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12667574215.html</link>
<pubDate>Fri, 09 Apr 2021 19:25:10 +0900</pubDate>
</item>
<item>
<title>.Net4.5(C#５) 非同期 async/await</title>
<description>
<![CDATA[ <p><span style="font-size:1em;"><a href="https://stat.ameba.jp/user_images/20210409/13/takanost/93/89/p/o0485032014923625426.png"><img alt="" height="277" src="https://stat.ameba.jp/user_images/20210409/13/takanost/93/89/p/o0485032014923625426.png" width="420"></a></span></p><p><span style="font-size:1em;">何か時間のかかる処理をしているとき、画面が固まってじっとしているしかない。<br>次のソースコードがその例である。</span></p><blockquote><div style="line-height:95%;"><p><span style="font-size:0.83em;">&nbsp; &nbsp; &nbsp; &nbsp; private void button1_Click(object sender, EventArgs e)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "開始";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Refresh();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HeavyWork();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "終了";<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; private void HeavyWork() //処理に時間のかかる関数を想定<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重い処理をしていると仮定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p></div></blockquote><p><span style="font-size:1em;">しかし、async/await を使って次のように書くと画面を動かしたり最大化したりできるようになる。</span></p><blockquote><div style="line-height:95%;"><p><span style="font-size:1em;">&nbsp; &nbsp; &nbsp; </span><span style="font-size:0.83em;">&nbsp;private <span style="background-color:#ffcc00;">async</span> void button2_Click(object sender, EventArgs e)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "開始";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color:#ffcc00;"> await</span> Task.Run(() =&gt; HeavyWork());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label1.Text = "終了";<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; private void HeavyWork() //処理に時間のかかる関数を想定<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //重い処理をしていると仮定<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.Sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; }</span></p></div></blockquote><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12667521655.html</link>
<pubDate>Fri, 09 Apr 2021 14:01:20 +0900</pubDate>
</item>
<item>
<title>C#のローカル関数</title>
<description>
<![CDATA[ <p>■ローカル関数<br>C#７では関数の中に関数を定義できる。これをローカル関数という。アクセスは親関数のみできる。</p><p>下記のファイルの着色部分がそうである。Main関数の中に関数が記入されている。</p><p>&nbsp;</p><blockquote><ol><li style="text-align: left;">using System;</li><li style="text-align: left;">&nbsp;</li><li style="text-align: left;">class Base { }</li><li style="text-align: left;">class Derived : Base { }</li><li style="text-align: left;">&nbsp;</li><li style="text-align: left;">class Program</li><li style="text-align: left;">{</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;delegate Base BaseDelegate();</li><li style="text-align: left;">&nbsp;</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;static void Main(string[] args)</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;{</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<span style="background-color:#ffcc00;">Derived SampleMethod()&nbsp;</span></li><li style="text-align: left;"><span style="background-color:#ffcc00;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{</span></li><li style="text-align: left;"><span style="background-color:#ffcc00;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Console.WriteLine("Derived");&nbsp;</span></li><li style="text-align: left;"><span style="background-color:#ffcc00;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return new Derived();&nbsp;</span></li><li style="text-align: left;"><span style="background-color:#ffcc00;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}</span></li><li style="text-align: left;">&nbsp;</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BaseDelegate theDelegate = SampleMethod;</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;theDelegate();</li><li style="text-align: left;">&nbsp;&nbsp; &nbsp;}</li><li style="text-align: left;">}</li><li style="text-align: left;">//OutPut: Derived</li></ol></blockquote>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12667352615.html</link>
<pubDate>Thu, 08 Apr 2021 16:36:43 +0900</pubDate>
</item>
<item>
<title>C# イベント　その１</title>
<description>
<![CDATA[ <h3>イベントの簡単な例</h3><p>今日も「独習C#」を読んで、勉強している。</p><p>イベントの書かれている第12章を読んでいるが、なかなか理解するのが難しい。</p><p>イメージとしては、次のようなものだ。</p><p>１．受信クラスと送信クラスを用意する。</p><p>２．受信クラスのイベントハンドラーを送信クラスに登録する。</p><p>３．受信クラスで何か起こすと送信クラスに火が着いて、イベントハンドラーが実行される。</p><p>イベントの例を最も簡単なコードで理解しよう。</p><blockquote><p><span style="font-size: 0.83em;">using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;</span></p><p><span style="font-size: 0.83em;">namespace Event1<br>{<br>&nbsp;&nbsp;&nbsp; // イベント用のデリゲートの宣言<br>&nbsp;&nbsp;&nbsp;<span style="background-color: rgb(255, 204, 0);"> public delegate void EventHandler(); </span>//←イベントで使うデリゲートを宣言する</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp; // イベントの送信側のクラス<br>&nbsp;&nbsp;&nbsp; class EventFire<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">public event EventHandler SomeEvent;</span> //←イベントを宣言する</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // イベント送信を実装したメソッド<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void Fire()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (SomeEvent != null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">SomeEvent(); </span>//←イベントを送信する<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; class Program<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Handler()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("<span style="color: rgb(255, 0, 0);">Event occurred</span>");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EventFire evt = new EventFire(); //←イベントを送信する側のインスタンスを作成する</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ハンドラをイベントリストに追加する<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">evt.SomeEvent += Handler;</span> //←イベントのチェーンにハンドラを追加する</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // イベントを人為的に発生させる<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evt.Fire(); //←イベントを発生させる</span></p><p><span style="font-size: 0.83em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.ReadKey();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</span></p><p><span style="font-size: 0.83em;">}</span></p></blockquote><p>実行結果は「<span style="color: rgb(255, 0, 0);">Event occurred</span>」と表示されるだけ。</p>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12440664619.html</link>
<pubDate>Sat, 16 Feb 2019 21:46:18 +0900</pubDate>
</item>
<item>
<title>C# デリゲート</title>
<description>
<![CDATA[ <p>C#のデリゲートを勉強した。</p><p>読んでいる本は「独習C#」。</p><p>デリゲートを英語で書けば、delegateだ。</p><p>delegateは代理人や代行者と言った意味。</p><p>早い話が、デリゲートとはメソッドを別の名前で実行する機能。</p><p>早速コードを見てみよう。</p><blockquote><p>// デリゲートの例<br>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;</p><p>namespace Delegate<br>{<br>&nbsp;&nbsp;&nbsp; // デリゲートの宣言<br>&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">delegate string OutputStr(string str); </span>//←OutputStrというデリゲートを宣言</p><p>&nbsp;&nbsp;&nbsp; class Program<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースをハイフンで置き換える<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static string ReplaceSpaces(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Replaces spaces with hyphens.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a.Replace(' ', '-');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースを取る<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static string RemoveSpaces(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Removing spaces.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; a.Length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (a[i] != ' ') temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 文字列の並びを逆転させる<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static string Reverse(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Reversing string.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //for (j = 0, i = a.Length - 1; i &gt;= 0; i--, j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = a.Length - 1; i &gt;= 0; i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // デリゲートを作成する<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">OutputStr method = ReplaceSpaces;</span> //←デリゲートのインスタンスを作成する<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //OutputStr method = new OutputStr(ReplaceSpaces);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // デリゲートを使ってメソッドを呼び出す<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test."); //←デリゲートを使ってメソッドを呼び出す</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method = RemoveSpaces;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //method = new OutputStr(RemoveSpaces);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method = Reverse;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //method = new OutputStr(Reverse);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.ReadKey();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</p></blockquote><p>実行結果</p><p><a href="https://stat.ameba.jp/user_images/20190216/00/takanost/55/4e/p/o0294015814356862034.png"><img alt="" height="158" src="https://stat.ameba.jp/user_images/20190216/00/takanost/55/4e/p/o0294015814356862034.png" width="294"></a></p><p>上記のコードではstaticメソッドを使用した例だが、次のようにインスタンスメソッドにも適用できる。</p><blockquote><p>// インスタンスメソッドのデリゲートの例<br>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;</p><p>namespace Delegate2<br>{<br>&nbsp;&nbsp;&nbsp; // デリゲートの宣言<br>&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">delegate string OutputStr(string str); </span>//←OutputStrというデリゲートを宣言</p><p>&nbsp;&nbsp;&nbsp; class SomeMethods<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースをハイフンで置き換える<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string ReplaceSpaces(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Replaces spaces with hyphens.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a.Replace(' ', '-');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースを取る<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string RemoveSpaces(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Removing spaces.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; a.Length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (a[i] != ' ') temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 文字列の並びを逆転させる<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string Reverse(string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Reversing string.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //for (j = 0, i = a.Length - 1; i &gt;= 0; i--, j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = a.Length - 1; i &gt;= 0; i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; class Program<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // インスタンス生成<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomeMethods some = new SomeMethods();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // デリゲートの作成<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">OutputStr method = some.ReplaceSpaces;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //OutputStr method = new OutputStr(some.ReplaceSpaces);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // デリゲートを使ってメソッドを呼び出す<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test."); //←デリゲートを使ってメソッドを呼び出す</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method = some.RemoveSpaces;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //method = new OutputStr(some.RemoveSpaces);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method = some.Reverse;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //method = new OutputStr(some.Reverse);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = method("This is a test.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.ReadKey();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</p></blockquote><p>実行結果ははじめの例と同じになる。</p><p>上で紹介したコードでは、デリゲートなんて何の役に立つのか疑問が残る。</p><p>次に学ぶマルチキャストや、明日学ぶイベントと言ったところでありがたみが分かる。</p><p>マルチキャストの説明をしよう。</p><p>マルチキャストとは、複数のメソッドをまとめて実行する機能である。</p><p>どういうものか、ソースを見てみよう。</p><blockquote><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;</p><p>namespace Multicast<br>{<br>&nbsp;&nbsp;&nbsp; // デリゲートの宣言<br>&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">delegate void OutputStr(ref string str); </span>//←OutputStrというデリゲートを宣言</p><p>&nbsp;&nbsp;&nbsp; class Program<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースをハイフンで置き換える<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void ReplaceSpaces(ref string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Replaces spaces with hyphens.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.Replace(' ', '-');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // スペースを取る<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void RemoveSpaces(ref string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Removing spaces.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; a.Length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (a[i] != ' ') temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 文字列の並びを逆転させる<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Reverse(ref string a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string temp = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Reversing string.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //for (j = 0, i = a.Length - 1; i &gt;= 0; i--, j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = a.Length - 1; i &gt;= 0; i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp += a[i];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // デリゲートの作成<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">OutputStr method;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str = "This is a test.";</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // マルチキャストの準備<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method = ReplaceSpaces;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method += Reverse;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // マルチキャストの呼び出し<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method(ref str);</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 置き換えのメソッドを取り除き、スペース削除のメソッドを追加する<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method -= ReplaceSpaces;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method += RemoveSpaces; //←別のマルチキャストを作成する</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = "This is a test.";　// 文字列を再度設定する</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // マルチキャストの呼び出し<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="background-color: rgb(255, 204, 0);">method(ref str);</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Resulting string: " + str);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.ReadKey();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</p></blockquote><p>実行結果</p><p><a href="https://stat.ameba.jp/user_images/20190216/00/takanost/af/b3/p/o0291015014356862036.png"><img alt="" height="150" src="https://stat.ameba.jp/user_images/20190216/00/takanost/af/b3/p/o0291015014356862036.png" width="291"></a></p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12440451128.html</link>
<pubDate>Fri, 15 Feb 2019 23:36:00 +0900</pubDate>
</item>
<item>
<title>Linux をインスト―ルしてみた</title>
<description>
<![CDATA[ <p>Ubuntu18.04.1をインストールしてみた。</p><p>&nbsp;</p><p>私の構築方法は次のようである。<br>１．Windows8.1にVirtualBox6.0をインストールする。<br>２．VirtualBoxにUbuntuをインストールする。</p><p>&nbsp;</p><p>Ubuntuは無事にインストールはされたものの、Ubuntuの画面が小さいままで、大きくできない。<br>そこで、ググって調べて直した。<br>直しかたはここ↓<br><a href="https://qiita.com/lion0506/items/36b9ce19724a32fbd1ac">https://qiita.com/lion0506/items/36b9ce19724a32fbd1ac</a></p><p>&nbsp;</p><p>また、Ubuntuのソフトエア更新にも失敗する。<br>この直し方は次の画面でダウンロード元のアドレスを変更してみたら直った。</p><p>&nbsp;</p><p><a href="https://stat.ameba.jp/user_images/20190214/19/takanost/17/fc/p/o0983055914356140400.png"><img alt="" contenteditable="inherit" height="239" src="https://stat.ameba.jp/user_images/20190214/19/takanost/17/fc/p/o0983055914356140400.png" width="420"></a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ↓</p><p><a href="https://stat.ameba.jp/user_images/20190214/19/takanost/08/f7/p/o0775055914356136110.png"><img alt="" height="303" src="https://stat.ameba.jp/user_images/20190214/19/takanost/08/f7/p/o0775055914356136110.png" width="420"></a></p><p>&nbsp;</p><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/takanost/entry-12440150426.html</link>
<pubDate>Thu, 14 Feb 2019 19:32:04 +0900</pubDate>
</item>
</channel>
</rss>
