C#
以下のページを元にがんばれ! 参考ページ http://c-loft.com/blog/?p=637 https://dobon.net/vb/dotnet/internet/webrequestsavefile.html
LINQってのを使う。 「LINQ は foreach のパワーアップ版」と考えるといいらしい var data = new[] { 0, 1, 2, 3, 4, 5, 6, 7 }; // LINQ if (data.Any()) { var first = data.First(); Console.WriteLine("最初にやる処理 {0}", first); foreach (var i in …
// "引数名は args です" と出力される Console.WriteLine($"引数名は {nameof(args)} です"); ネタ元 http://fernweh.jp/b/csharp-nameof-operator/
usingにSystem.Configurationを追加するだけではダメで、プロジェクトの参照から追加する必要がある。参照追加方法 「ソリューションエクスプローラー」→「参照」右クリック→「参照の追加」アセンブリ:フレームワーク内にある「System.Configuration」にチ…
設定はプロジェクトファイルのApp.config に組み込む方法のほうが好きかな。 ネタ元 http://blog.hiros-dot.net/?p=5461 https://qiita.com/rohinomiya/items/2b86c4e8d5afd5c2fb39
string filename = Path.GetFileName(sourceFilePath); ネタ元 http://www.atmarkit.co.jp/ait/articles/0405/28/news083.html
ログ出し用に使えますね。.Net4.5から用っぽい public void Debug(string mess, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runt…
設定ファイルを別途置かないやり方。AssemblyInfo.cs に追記 // read Log4Net Configuration file [assembly: log4net.Config.XmlConfigurator(Watch = true)]App.Configに以下追記 <configuration> ... <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> ... </configuration>
フォームのクラスで これだけ this.Text = "新しいタイトル"; ネタ元 https://www.itlab51.com/?p=2526
デザイナーを使用してイベント ハンドラーを作成できるよ ネタ元 https://msdn.microsoft.com/ja-jp/library/zwwsdtbk(v=vs.110).aspx https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.form.shown?redirectedfrom=MSDN&view=netframework…
ネタ元 http://eno0514.hatenadiary.jp/entry/20150820/1440012050
Progress という名前のフォームを作って、 プログレスバー(progressBar1) と キャンセルボタン(button1)を貼り付ける。 コードは以下のように。 処理するのは文字列返す関数としている。Progress.cs // SetTitle() / SetFunction() で処理設定して ShowDialo…
NuGetでSelenium.SupportとSelenium.WebDriverをインストールして 実行ファイルと同じフォルダにMicrosoftWebDriver.exeがある前提。 MicrosoftWebDriver.exeはこちらからDL。 var service = EdgeDriverService.CreateDefaultService(); service.HideCommand…
using System; using System.Security.Cryptography; public void CreateKey1(out string iv, out string key) { var BLOCK_SIZE = 128; // 128bit 固定 var KEY_SIZE = 256; // 128/192/256bit から選択 // AES暗号サービスを生成 var csp = new AesCryptoS…
byte[] input = Encoding.ASCII.GetBytes("hogehogehoge"); SHA256 sha = new SHA256CryptoServiceProvider(); byte[] hash_sha256 = sha.ComputeHash(input); ネタ元 https://www.ipentec.com/document/csharp-get-sha256-string
string client_id = "hogehoge"; // 提供される情報 string client_secret = "hogehoge_secret"; // HttpClient http_client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(); request.Method = HttpMethod.Post; request.Reque…
// フォルダ (ディレクトリ) を作成する System.IO.Directory.CreateDirectory(@"C:\Hoge\Foo\") // 作成先の DirectoryInfo を取得することも可能 System.IO.DirectoryInfo hDirInfo; hDirInfo = System.IO.Directory.CreateDirectory(@"C:\Hoge\Bar\"); ネ…
// フォルダ (ディレクトリ) が存在しているかどうか確認する if (System.IO.Directory.Exists(@"C:\Hoge\")) { MessageBox.Show("ディレクトリは存在します"); } else { MessageBox.Show("ディレクトリは存在しません"); } ネタ元 http://jeanne.wankuma.co…
CsvHelperというモジュールがあるらしい。使ってみようかな ネタ元 https://webbibouroku.com/Blog/Article/csvhelper-read
aaa_2017_8411.csvというファイル名で、2つ目の数字4文字が欲しいサンプル System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(item, @"\d{4}"); string code = mc[1].Value; ネタ元 https://dobon.net/vb/…
using System.IO; ... string[] files = Directory.GetFiles( search_path, "*.csv", SearchOption.AllDirectories); ネタ元 https://dobon.net/vb/dotnet/file/getfiles.html でもDirectory.EnumerateFilesのほうが高速でいいらしいよ。 ネタ元 http://dev.…
らしい。 つかってみようかな。 ネタ元 https://qiita.com/matarillo/items/a92e7efbfd2fdec62595
正規表現で数字だけ抜き出す。 using System.Text.RegularExpressions; string str = Regex.Replace (gameObject.name, @"[^0-9]", ""); Debug.Log (str); ネタ元 http://robamemo.hatenablog.com/entry/2018/03/03/194425
foreach (MyItem item in items.Reverse()) { // itemに対する処理ここで行う } ネタ元 https://blog.yuizi.com/2010/04/c_9105.html
Dictionaryの代わりにSortedDictionaryを利用すると、自動でキーを元にソートしてくれます。例 // 宣言:SortedDictionaryとしてインスタンスを作成 var itemTable = new SortedDictionary<int, Item>(); ネタ元 https://takachan.hatenablog.com/entry/2018/04/02/2324</int,>…
オブジェクト はJObject 配列はJArray 文字列や数値はJValue配列のループはこんな感じ JArray jarr = (JArray)jres["results"]; foreach (JObject jobj in jarr) { JValue nameValue = (JValue)jobj["name"]; string name = (string)nameValue; JValue price…
データ型 サフィックス 数値の有効範囲 int型(System.Int32型) なし 符号付き32bit整数値。-2147483648 ~ 2147483647 uint型(System.UInt32型) u(もしくは、U) 符号なし32bit整数値。0 ~ 4294967295 long型(System.Int64型) L(もしくは、l) 符号…
WebClientでアクセスしたら例外がでた。 TLS1.0、1.1の廃止が原因らしい。TLS1.2にするには ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 入れるだけで一応OK。 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12…
// キー入力を待つ(止める目的なら、どっちでも良い) Console.ReadLine(); Console.ReadKey(); ネタ元 http://www.remember-the-time.xyz/2012/06/c.html
GCHandle構造体を使うといいらしい。 [DllImport("hogehoge.dll")] private static extern int dll_TestFunc(int frameno, IntPtr ary, int aryCount); public int TestFunc(int frameno, ref float[] ary) { int len = ary.Length; GCHandle gcH = GCHandle…