X



ふらっと C#,C♯,C#(初心者用) Part148

■ このスレッドは過去ログ倉庫に格納されています
2020/05/27(水) 10:14:39.92ID:wHIUQvvs
■前スレ
ふらっと C#,C♯,C#(初心者用) Part147
http://mevius.5ch.net/test/read.cgi/tech/1582100741/
■関連スレ
C#, C♯, C#相談室 Part94
http://mevius.5ch.net/test/read.cgi/tech/1553075856/
■コードを貼る場合は↓を使いましょう。
http://ideone.com/
https://dotnetfiddle.net/

■情報源
https://docs.microsoft.com/ja-jp/dotnet/standard/class-libraries
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/index
https://docs.microsoft.com/en-us/dotnet/standard/class-libraries
http://referencesource.microsoft.com/
・Insider.NET > .NET TIPS - @IT
https://www.atmarkit.co.jp/ait/subtop/features/dotnet/dotnettips_index.html
・DOBON.NET .NET Tips
https://dobon.net/vb/dotnet/index.html
2020/07/07(火) 22:09:21.93ID:Qy5BOzav
>>442
デリゲートは参照型だからなのでは
2020/07/07(火) 22:32:42.82ID:wq2UphxJ
ラムダ式を2個書いてるから、それぞれ別のオブジェクト
それを比較してるから同じではない

その比較はデリゲート同士の比較なんだが、もしかして整数同士の比較だと思ってる?
2020/07/07(火) 22:35:09.13ID:auzHn+nI
ラムダ式が同じ式でも別メソッドにコンパイルされてるからfalseになってる

int twice(int x) => x * 2;
Func<int, int> a = new Func<int, int>(twice);
Func<int, int> b = new Func<int, int>(twice);
var flg = a == b; // これなら同じメソッドだからtrue

Func<int, int> a = p => p * 2;
Func<int, int> b = p => p * 2;
はこんな感じになる
class __c {
public static readonly __c __instance = new __c();
public int __1(int p) => p * 2;
public int __2(int p) => p * 2;
}
Func<int, int> a = new Func<int, int>(__c.__instance.__1);
Func<int, int> b = new Func<int, int>(__c.__instance.__2);
var flg = a == b; // __1と__2で別メソッドなのでfalse
■ このスレッドは過去ログ倉庫に格納されています
5ちゃんねるの広告が気に入らない場合は、こちらをクリックしてください。

ニューススポーツなんでも実況