タグ付けされた質問 「c#」

C#(「seesharp」と発音)は、Microsoftによって開発された、静的に型指定された高レベルのマルチパラダイムプログラミング言語です。C#コードは通常、Microsoftの.NETファミリのツールとランタイムを対象としています。これには、.NET Framework、.NET Core、Xamarinなどが含まれます。このタグは、C#またはC#の正式な仕様で記述されたコードに関する質問に使用します。



5
「空の」C#ラムダ式を指定する方法はありますか?
何もしない "空の"ラムダ式を宣言したいのですが。DoNothing()メソッドを必要とせずにこのようなことをする方法はありますか? public MyViewModel() { SomeMenuCommand = new RelayCommand( x => DoNothing(), x => CanSomeMenuCommandExecute()); } private void DoNothing() { } private bool CanSomeMenuCommandExecute() { // this depends on my mood } これを行う私の意図は、WPFコマンドの有効/無効状態を制御することだけですが、それはさておきです。多分それは私にとって早すぎる時期ではあるかもしれませんがx => DoNothing()、同じことを達成するためにこのような方法でラムダ式を宣言するだけの方法があるはずだと思います: SomeMenuCommand = new RelayCommand( x => (), x => CanSomeMenuCommandExecute()); これを行う方法はありますか?何もしないメソッドを必要とする必要はないようです。
118 c#  lambda 

3
カスタム構成ファイルの読み込み
静的ConfigurationManager.OpenExe(exePath)メソッドを使用してアセンブリに関連する構成ファイルを開くことができることはわかっていますが、アセンブリに関連しない構成を開きたいだけです。ただの標準的な.NET構成ファイル。
118 c#  configuration 

6
JavaのcharAt()と同等のC#?
charAt()Javaでこのメソッドを使用して、位置を指定することで文字列内の個々の文字を取得できることを知っています。C#に同等のメソッドはありますか?
118 c#  java  string 

11
.NETの一意のオブジェクト識別子
インスタンスの一意の識別子を取得する方法はありますか? GetHashCode()同じインスタンスを指す2つの参照で同じです。ただし、2つの異なるインスタンスが(かなり簡単に)同じハッシュコードを取得できます。 Hashtable hashCodesSeen = new Hashtable(); LinkedList<object> l = new LinkedList<object>(); int n = 0; while (true) { object o = new object(); // Remember objects so that they don't get collected. // This does not make any difference though :( l.AddFirst(o); int hashCode = o.GetHashCode(); n++; if (hashCodesSeen.ContainsKey(hashCode)) …

4
「async void」イベントハンドラーを回避する必要がありますか?
async void保留中のタスクの追跡がなく、このようなメソッド内でスローされる可能性のある例外を処理するのが難しいため、タスクを開始するためにファイアアンドフォーゲットメソッドを使用することは、一般的に悪い考えと考えられます。 通常、async voidイベントハンドラーも回避する必要がありますか?例えば、 private async void Form_Load(object sender, System.EventArgs e) { await Task.Delay(2000); // do async work // ... } 次のように書き直すことができます。 Task onFormLoadTask = null; // track the task, can implement cancellation private void Form_Load(object sender, System.EventArgs e) { this.onFormLoadTask = OnFormLoadTaskAsync(sender, e); } private async Task OnFormLoadTaskAsync(object sender, …

9
.net Func <T>を.net Expression <Func <T >>に変換する
ラムダから式への移行は、メソッド呼び出しを使用すると簡単です... public void GimmeExpression(Expression&lt;Func&lt;T&gt;&gt; expression) { ((MemberExpression)expression.Body).Member.Name; // "DoStuff" } public void SomewhereElse() { GimmeExpression(() =&gt; thing.DoStuff()); } しかし、私はFuncを式に変えたいのですが、まれなケースだけです... public void ContainTheDanger(Func&lt;T&gt; dangerousCall) { try { dangerousCall(); } catch (Exception e) { // This next line does not work... Expression&lt;Func&lt;T&gt;&gt; DangerousExpression = dangerousCall; var nameOfDanger = ((MemberExpression)dangerousCall.Body).Member.Name; throw new DangerContainer( …
118 c#  .net  lambda  expression  func 

4
DataRowをコピーまたは複製する簡単な方法は?
DataRowのクローンを作成する簡単な方法を探しています。そのロウのスナップショットを撮って保存するようなものです。元の行の値は自由に変更できますが、変更されていない別の保存されたコピーがあります。これは正しい方法ですか? DataRow Source, Destination; // Assume we create some columns and fill them with values Destination.ItemArray = Source.ItemArray; これは、スナップショットのItemArray参照をSourceの参照を指すように設定するだけですか、それとも実際に別のコピーを作成しますか?代わりにこれを行う必要がありますか? Destination.ItemArray = Source.ItemArray.Clone(); 編集:2番目のコードスニペットが実際にコンパイルされるとは思いません。
118 c#  datatable  datarow 

5
Json.netを使用したJSONオブジェクト配列の逆シリアル化
返されたjsonに次のサンプル構造を使用するAPIを使用しようとしています [ { "customer":{ "first_name":"Test", "last_name":"Account", "email":"test1@example.com", "organization":"", "reference":null, "id":3545134, "created_at":"2013-08-06T15:51:15-04:00", "updated_at":"2013-08-06T15:51:15-04:00", "address":"", "address_2":"", "city":"", "state":"", "zip":"", "country":"", "phone":"" } }, { "customer":{ "first_name":"Test", "last_name":"Account2", "email":"test2@example.com", "organization":"", "reference":null, "id":3570462, "created_at":"2013-08-12T11:54:58-04:00", "updated_at":"2013-08-12T11:54:58-04:00", "address":"", "address_2":"", "city":"", "state":"", "zip":"", "country":"", "phone":"" } } ] JSON.netは次のような構造でうまく機能します { "customer": { ["field1" : "value", etc...], ["field1" …
118 c#  json.net 

2
.NET Coreのオペレーティングシステムを確認する
.NET Coreアプリが実行されているオペレーティングシステムを確認するにはどうすればよいですか?以前は使用できましたEnvironment.OSVersion。 アプリがMacとWindowsのどちらで実行されているかを確認する現在の方法は何ですか?
118 c#  .net-core 

7
Entity Framework Migrationsがテーブルとカラムの名前を変更
いくつかのエンティティとそのナビゲーションプロパティの名前を変更し、EF 5で新しい移行を生成しました。EF移行での名前の変更と同様に、デフォルトでは、オブジェクトを削除して再作成していました。それは私が欲しかったものではないので、移行ファイルをゼロから構築しなければなりませんでした。 public override void Up() { DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports"); DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups"); DropForeignKey("dbo.Editables", "Section_Id", "dbo.ReportSections"); DropIndex("dbo.ReportSectionGroups", new[] { "Report_Id" }); DropIndex("dbo.ReportSections", new[] { "Group_Id" }); DropIndex("dbo.Editables", new[] { "Section_Id" }); RenameTable("dbo.ReportSections", "dbo.ReportPages"); RenameTable("dbo.ReportSectionGroups", "dbo.ReportSections"); RenameColumn("dbo.ReportPages", "Group_Id", "Section_Id"); AddForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports", "Id"); AddForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections", "Id"); AddForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages", "Id"); …


4
C#クラスプロパティを反復処理する
現在、クラスオブジェクトのすべての値を設定していますRecord。 これは、現時点でレコードを入力するために、プロパティごとに使用しているコードです。 // Loop through each field in the result set for (int i = 0; i &lt;= resultItems.Length; i++) { Record newRecord = new Record() { itemtype = resultItems[i - (fieldCount - 0)], itemdesc = resultItems[i - (fieldCount - 1)], prodcode = resultItems[i - (fieldCount - 2)], proddesc = …
118 c#  properties  loops 

15
これは技術的には「Hello World」のO(1)アルゴリズムですか?
これは「Hello、World!」のO(1)アルゴリズムとして分類されますか??? public class Hello1 { public static void Main() { DateTime TwentyYearsLater = new DateTime(2035,01,01); while ( DateTime.Now &lt; TwentyYearsLater ) { System.Console.WriteLine("It's still not time to print the hello ..."); } System.Console.WriteLine("Hello, World!"); } } 私は使用することを考えています DateTime TwentyYearsLater = new DateTime(2035,01,01); while ( DateTime.Now &lt; TwentyYearsLater ) { // …
117 c#  .net  algorithm  big-o 

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.