(this IEnumerable
// 概要:
// 条件を満たす、指定されたシーケンス内の要素の数を表す数値を返します。
//
// パラメーター:
// source:
// テストおよびカウントする要素が格納されているシーケンス。
//
// predicate:
// 各要素が条件を満たしているかどうかをテストする関数。
//
// 型パラメーター:
// TSource:
// source の要素の型。
//
// 戻り値:
// 述語関数の条件を満たす、シーケンス内の要素数を表す数値。
//
// 例外:
// System.ArgumentNullException:
// source または predicate が null です。
//
// System.OverflowException:
// source 内の要素数が System.Int32.MaxValue を超えています。
using System;
using System.Linq;
namespace SampleCode {
class Program {
static void Main(string[] args) {
string test = "gooooooooooooooooooooooooooogle";
//LINQで oの個数を調べる
int count = test.Count(c => c == 'o'); //ラムダ式を渡す
Console.WriteLine("oの数は{0}個です", count); //oの数は27個です
}
}
}
0 件のコメント:
コメントを投稿