[過去ログ] ふらっと C#,C♯,C#(初心者用) Part155 (1002レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
164: デフォルトの名無しさん (ワッチョイ 4f02-lwqN) [] 2022/06/27(月) 15:08:18.79 ID:Kbl5ft5+0(1/5) AAS
インターフェースのメンバーを呼び出す時には実装を確認すべきなのでしょうか
それとも 定義元のインターフェースへのキャスト必須ですか
(例)
class MyList : IList<int>
{
int IContainer<int> Count { get; }
...
...
}
165: 164 (ワッチョイ 4f02-lwqN) [sage] 2022/06/27(月) 15:22:13.53 ID:Kbl5ft5+0(2/5) AAS
ドットが抜けてました
int IContainer<int>.Count { get; }
166: 164 (ワッチョイ 4f02-lwqN) [sage] 2022/06/27(月) 15:33:45.50 ID:Kbl5ft5+0(3/5) AAS
ぐちゃぐちゃですみません
int ICollection<int>.Count { get; }
168: 164 (ワッチョイ 4f02-lwqN) [sage] 2022/06/27(月) 20:38:42.94 ID:Kbl5ft5+0(4/5) AAS
>>167var mylist = new MyList();
var c0 = mylist.Count; // build error
// MyList は IList<int> : ICollection<int> をもつので
var c1 = ((ICollection<int>)mylist).Count;
// MListでint ICollection<int>.Count { get; } という memberをもつので
var c2 = ((ICollection<int>)mylist).Count;
c1は 万能
171: 164 (ワッチョイ 4f02-lwqN) [sage] 2022/06/27(月) 22:21:47.30 ID:Kbl5ft5+0(5/5) AAS
>>169 >>170170(1): デフォルトの名無しさん (ワッチョイ ffbc-qwBH) [sage] 2022/06/27(月) 21:49:28.21 ID:oKLZ5l1i0(1/2) AAS
IList.Count って public int Count { get } じゃなかったっけ。
((ICollection<int>)mylist).Count; が出来るのは、別途 ICollection.Count が実装されているからじゃないの。
var array = new int[]{1,2,3};
var c0 = array.Count; // build error
var collection = (ICollection<int>)array;
var c1 = collection.Count; // ok
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.037s