2015-10-13 210 views
-1
/* 

Instructions 
------------ 
Write a LINQ query that results in all fruits that are a single word (i.e. exclude fruits like "Goji berries", as well as empty entries). 
Sort the results by the length of the word, with the longest word first and the shortest word last. 
The results should be lowercased. 

*/ 

using System; 
using System.Linq; 

public class Program 
{ 
    static readonly string[] Fruits = new [] 
    { 
     "Acai", 
     "Apple", 
     "Apricots", 
     "Banana", 
     "Blackberry", 
     "", 
     "Blueberry", 
     "Cherries", 
     "Coconut", 
     "Cranberry ", 
     "Cucumber", 
     "Currents", 
     "Dates", 
     "Durian", 
     "Fig", 
     "Goji berries", 
     "Gooseberry", 
     "Grapefruit", 
     "Grapes", 
     "Jackfruit", 
     "Kiwi", 
     "Kumquat", 
     "Lemon", 
     "Lime", 
     "Lucuma", 
     " Lychee", 
     "Mango", 
     "Mangosteen", 
     "Melon", 
     "", 
     "Mulberry", 
     "Nectarine", 
     "Orange", 
     "Papaya", 
     "Passion Fruit", 
     "Peach", 
     "Pear", 
     "Pineapple ", 
     "Plum", 
     "Pomegranate", 
     "Pomelo", 
     "Prickly Pear", 
     "Prunes", 
     "Strawberries", 
     "Tangerine", 
     "Watermelon" 
    };) 

    public void Main() 
    { 
     // Do your work here... 
[] 

     Console.WriteLine("Answer: {0}", String.Join("*", new); 
    } 
} 

這是怎麼回事?我不知道我明白了。這裏有什麼解決方案?字符串連接問題

我正在嘗試各種方法,但該方法似乎並不支持這裏所做的一切。

任何幫助或指導,非常感謝。

我有點迷失在這一個。

感謝您的任何幫助。

+1

'「的string.join(」 *」,新)「' - 你甚至想在這裏用關鍵詞'new'做什麼?你不是想加入數組'Fruits'嗎?此外,「WTF」並不是真正有意義的問題描述。我們無法看到您的屏幕。顯示您收到的錯誤,解釋您正在嘗試的內容以及原因等。 – David

回答

0

您缺少一行中的),您不應將關鍵字new用作變量名稱。

Console.WriteLine("Answer: {0}", String.Join("*", result)); 

在你指定的部分中,你將創建變量並將結果賦值給它。

這不能解決分配,而不是它獲得的第三種水果,但它展示瞭如何創建變量並使用數據進行工作:

string[] result = Fruits.Take(3).ToArray();