String [] arrStr={" a ", "b", "c"};
Return arrStr. Count (p=& gt; P==STR);
String [] type can use the count, was because it inherits the IEnumerable
Interface (not found), and then System. Linq Enumerable class in the extension of the interface with the count function, so I can call Question, why can't find the generic interface (I am looking for in the Array class, string [] after all is an Array type), or that sentence is wrong (it need not inherit IEnumerable Interface can also be called the linq extension methods (certainly wrong)) If you find where inheritance, the post code or screenshot If that sentence is wrong, it also tell me where is wrong, what is the correct CodePudding user response:
After suggested answer , look at the C IEnumerable CodePudding user response:
Eldest brother,,,, I have sent on a stick figure,,, You aim at the Count a f12 in the past, you can see, is the extension method,,, This is not inherited,,,, CodePudding user response:
The Count nature of the extension method is a generic Count But the compiler is concluded that the string type for you, So you have written the Count (x=& gt; . ) But look at the picture you will know that CodePudding user response:
String [] is a generic array, is to implement the IEumerable<& gt; The, CodePudding user response:
refer to the second floor is nu month god reply: eldest brother,,,, I have sent on a stick figure,,, You aim at the Count a f12 in the past, you can see, is the extension method,,, This is not inherited,,,, There is something wrong with the eldest brother is my expression? You carefully look at the problem, I ask is a string [] types where IEnumerable< inheritance; T> Interface, not how to implement the count function, I don't care about that CodePudding user response:
refer to the second floor is nu month god reply: eldest brother,,,, I have sent on a stick figure,,, You aim at the Count a f12 in the past, you can see, is the extension method,,, This is not inherited,,,, Now not extension method that problem, the count of the extension method is only for IEnumerable Extension interface, also only IEnumerable Interface to the method call, now is your string [] see IEnumerable< inheritance; T> Interface, also can call, this is the problem, you have a good look at, also see post # 2 CodePudding user response:
reference 6 buildings have water, cold response: Quote: refer to the second floor is nu month god reply: Eldest brother,,,, I have sent on a stick figure,,, You aim at the Count a f12 in the past, you can see, is the extension method,,, This is not inherited,,,, Now not extension method that problem, the count of the extension method is only for IEnumerable Extension interface, also only IEnumerable Interface to the method call, now is your string [] see IEnumerable< inheritance; T> Interface, also can call, this is the problem, you have a good look at, also look at the posts of the # 2 CodePudding user response:
references on 7th floor is wrath of god reply: Quote: refer to the sixth floor have water, cold response: Quote: refer to the second floor is nu month god reply: Eldest brother,,,, I have sent on a stick figure,,, You aim at the Count a f12 in the past, you can see, is the extension method,,, This is not inherited,,,, Now not extension method that problem, the count of the extension method is only for IEnumerable Extension interface, also only IEnumerable Interface to the method call, now is your string [] see IEnumerable< inheritance; T> Interface, also can call, this is the problem, you have a good look at, also look at the posts of the # 2 This is can't see the IEnumerable< in Array class; T> The reason of the interface? CodePudding user response:
refer to the eighth floor have water, cold response: This is can't see the IEnumerable< in Array class; T> The reason of the interface? Array is a base class, an abstract class, Int [], string [], float []... Is he a derived class, Somebody else derived class in the realization of interface of extra, have what can't? You look at an Array of inheritance and interfaces, see IList And so on also is very normal, CodePudding user response:
GetEnumerator enough, You can realize your enumeration class, for example: Public static class MyStringExt { Public static int Count (this MyString thiz, Func Fun) { int count=0; The foreach (var c in thiz) { If (fun (c)) {count++; } } return count; } } Public class MyString { Private string _value; Public MyString (string value) { _value=https://bbs.csdn.net/topics/value; } Public IEnumerator GetEnumerator () { If (_value=null https://bbs.csdn.net/topics/={throw new Exception (" no enumeration set "); } The foreach (var c in _value) { Yield return c; } } The static void Main (string [] args) { MyString STR=new MyString (" hello "); Console. WriteLine (STR) Count (a=& gt; A=='l')); } } CodePudding user response:
references are anger, 9/f, in god's response: Quote: refer to the eighth floor have water, cold response: This is can't see the IEnumerable< in Array class; T> The reason of the interface? Array is a base class, an abstract class, Int [], string [], float []... Is he a derived class, Somebody else derived class in the realization of interface of extra, have what can't? You look at an Array of inheritance and interfaces, see IList And so on also is very normal, Eldest brother, can stick a figure or code CodePudding user response:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull