2013-07-31 18 views
-6
using System; 
namespace MyCSharpLearning 
{ 
    class StringProject 
    { 
     public int LargestSentenceInformation(string i) 
     { 
      string[] txt = i.Split(new char[] { '.', '?', '!', ',' }); 
      var largeS=txt.Order   
     } 
     public static void Main(string[] args) 
     { 
      StringProject n = new StringProject(); 
      string str1 = Console.ReadLine();   
      Console.ReadLine(); 
     } 
    } 
} 
+4

请问一个连贯的问题 – bengoesboom

+0

格式化.....谢谢你正在编辑的人。 –

+0

我是C#编程新手。我想要如何编写代码“哪个句子最大,哪个单词包含”。 thnx – Hossain

回答

0

你已经快到了。

string[] txt = i.Split(new char[] { '.', '?', '!', ',' }); //this part you had correct 
var stringsOrderedByLargest = txt.OrderByDescending(s => s.length); 

stringsorderedByLargest将现在包含从最长的排序,以最短:如果您使用System.Linq的命名空间,这是最简单的。如果你想计算一个字符串有多少个单词,只需要进行另一次分割,但是这次在''上查看结果集合的Count属性。

相关问题