//Linq的写法
using System;
using System.Linq;
namespace ConTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入字符串:");
string input = Console.ReadLine();
var result = from c in input group c by c into g select g;
foreach(var t in result)
{
Console.WriteLine("{0},{1}",t.Key,t.Count());
}
Console.Read();
}
}
}
using System;
using System.Linq;
namespace ConTest
{
class Program
{
static void Main(string[] args)
{
//求任意字符串长度,不同字符以及字符的总数
Console.WriteLine("请输入字符串:");
string input = Console.ReadLine();
string[] stores = input.GroupBy(g =>g).Select(t=>string.Format("{0},总数:{1}",t.Key,t.Count())).ToArray();
Array.ForEach(stores, t => Console.WriteLine(t));
Console.Read();
}
}
}