| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
2,031 バイト追加 、 2023年7月26日 (水) 02:13
====Win32 API DLL の利用====
*[[C Sharp Win32 API および DLL の利用 | C# Win32 API および DLL の利用]]
*[https://www.typea.info/blog/index.php/2022/07/27/net6_user32_dll_setwindowshookex_error_126/ .NET6 の Windows Formsから user32.dllの SetWindowsHookEx を呼び出すが ERROR_MOD_NOT_FOUND(126) エラーになる対処]
 
===[[Windows]] Forms===
====[[C Sharp Windows Forms Tips | C# Windows Forms Tips]]====
==[[Tips]]==
===日付のパース===
*https://docs.microsoft.com/ja-jp/dotnet/api/system.datetime.tryparseexact?view=net-6.0
<pre>
public static readonly string DATETIME_FORMAT_ISO8601 = "yyyy-MM-ddTHH:mm:ss.fffZ";
 
DateTime.ParseExact(
param.value,
DateTimeUtil.DATETIME_FORMAT_ISO8601,
System.Globalization.CultureInfo.InvariantCulture));
</pre>
 
 
===属性の指定と読み込み===
[https://docs.microsoft.com/ja-jp/dotnet/csharp/programming-guide/concepts/attributes/accessing-attributes-by-using-reflection リフレクションを使用した属性へのアクセス]
 
* 属性定義
<pre>
[System.AttributeUsage(System.AttributeTargets.Property)]
public class PrimaryKeyAttribute : System.Attribute
{
}
</pre>
 
*読み出し(Hogeクラスのプロパティに属性をつけているとする)
<pre>
var type = typeof(Hoge);
var properties = type.GetProperties();
foreach(var property in properties)
{
foreach(var attr in property.GetCustomAttributes(true))
{
Console.WriteLine($"[{attr}]");
}
Console.WriteLine($"{property.Name}");
}
</pre>
 
===Docコメント===
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/xmldoc/recommended-tags
}
</pre>
 
===HttpClient Query String===
var param = (new FormUrlEncodedContent(dict)).ReadAsStringAsync().GetAwaiter().GetResult();
===文字列配列を結合してCSVを作成===
string[] row = 文字列配列
return string.Join(GetDelimiters(), row.Select(f => $"\"{f}\"").ToArray());
</pre>
 
*¥{0¥} を生成する場合
<pre>
var i = 0;
var fmt = @$"¥{{{i}¥}}";
</pre>
}
}
 
===リストのシャッフル===
<pre>
list = list.OrderBy(m => Guid.NewGuid()).ToList();
</pre>
 
===ファイルを読んで書く===
<pre>
var inPath = @"...";
var outPath = @"...";
 
using (var writer = File.CreateText(outPath))
{
var lines = File.ReadAllLines(inPath).ToList();
lines.ForEach(line => {
writer.WriteLine(line);
});
}
</pre>
 
===ディレクトリのファイル処理===
<pre>
Directory.GetFiles(dirPath).ToList().ForEach( path => {
var name = Path.GetFileName(path);
 
});
</pre>
[[category:プログラミング言語]]

案内メニュー