下面是我班的代碼。該代碼創建一個ArrayList。然後它將一些「PipesList」添加到ArrayList中,在每個列表中添加管道。根據條件從列表中刪除項目
我想寫一個方法-RemoveTheSmallPipes來擺脫長度小於19的所有管道。爲此,我寫了一段我不知道有效的代碼!作爲代碼拋出錯誤:
Compiler Error Message: CS0050: Inconsistent accessibility: return type 'System.Collections.Generic.List' is less accessible than method 'Program.RemoveTheSmallPipes(System.Collections.Generic.List)'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Program
{
static void Main(string[] args)
{
List<PipesList> lstPipeTypes = new List<PipesList>();
lstPipeTypes.Add(new PipesList("PVC Pipes"));
lstPipeTypes[0].Pipes.Add(new Pipe("The blue pipe", 12));
lstPipeTypes[0].Pipes.Add(new Pipe("The red pipe", 15));
lstPipeTypes[0].Pipes.Add(new Pipe("The silver pipe", 6));
lstPipeTypes[0].Pipes.Add(new Pipe("The green pipe", 52));
lstPipeTypes.Add(new PipesList("Iron Pipes"));
lstPipeTypes[1].Pipes.Add(new Pipe("The gold pipe", 9));
lstPipeTypes[1].Pipes.Add(new Pipe("The orange pipe", 115));
lstPipeTypes[1].Pipes.Add(new Pipe("The pink pipe", 1));
lstPipeTypes.Add(new PipesList("Chrome Pipes"));
lstPipeTypes[2].Pipes.Add(new Pipe("The grey pipe", 12));
lstPipeTypes[2].Pipes.Add(new Pipe("The black pipe", 15));
lstPipeTypes[2].Pipes.Add(new Pipe("The white pipe", 19));
lstPipeTypes[2].Pipes.Add(new Pipe("The brown pipe", 60));
lstPipeTypes[2].Pipes.Add(new Pipe("The peach pipe", 16));
lstPipeTypes = RemoveTheSmallPipes(lstPipeTypes);
foreach (var pipeList in lstPipeTypes)
{
Console.WriteLine("PipesList: {0}", pipeList.pipeType);
foreach (var pipe in pipeList.Pipes)
{
Console.WriteLine("{0}, length: {1}", pipe.name, pipe.length);
}
Console.WriteLine();
}
Console.WriteLine("Done, press return to exit");
Console.ReadLine();
}
public static List<PipesList> RemoveTheSmallPipes(List<PipesList> lstPipeTypes)
{
//Place your code in here
//It should remove all pipes that have lengths lower than 19.
foreach (var pipeList in lstPipeTypes)
{
foreach (var pipe in pipeList.Pipes)
{
lstPipeTypes.RemoveAll(i => pipe.length < 19);
}
}
return lstPipeTypes;
}
}
class PipesList
{
public string pipeType;
public List<Pipe> Pipes;
public PipesList(string newBoxType)
{
pipeType = newBoxType;
Pipes = new List<Pipe>();
}
}
class Pipe
{
public string name;
public float length;
public Pipe(string newName, float newLength)
{
this.name = newName;
this.length = newLength;
}
}
這個問題是初步測試的一部分,我的公司(Xibis,www.xibis.com,我們在右邊做廣告>>)在開發者候選人到他們面前進行更復雜的測試後,確保他們具有基礎開發技能的基礎,所以我們不會浪費時間或候選人時間。對於考慮使用以下答案的任何考生,我們都知道這些答案,所以如果您以自己的身份提交答案,您將不會被邀請參加內部考試。請嘗試自行回答問題。 –
我無法得到答案。我在這裏問了這個問題,這樣我就可以知道如何解決這樣的錯誤,並且如果我面臨類似的錯誤,可以記住將來的錯誤。 –
我投票結束這個問題作爲題外話,因爲它是我們的公司初步測試的一部分,我們在邀請他們進行內部測試之前給予考生。 –