好吧我正在使用getSharedPreferences来存储我的高分,但是在我填写之前我想通过和数组将分数按升序排序,但是如果它在第一个pos中找到的分数小于它,则它不会检查其余的最小的?
//function to add score to array and sort it
public void addscoretoarray(int mScore){
for(int pos = 0; pos< score.length; pos++){
if(score[pos] > mScore){
//do nothing
}else {
//Add the score into that position
score[pos] = mScore;
break;
}
}
sortArray(score);
}
Run Code Online (Sandbox Code Playgroud)
我应该在循环之前和之后调用sortArray()来解决这个问题,还是有更好的方法来实现相同的结果?
我还要提一下,sortArray(得分)函数只是调用Arrays.sort(得分),其中得分是mScore数组
编辑:根据@Vincent Ramdhanie发布的内容,我修改了帖子:
public void addscoretoarray(int mScore){
int pos = score.length;
//sort the array (in ascending order)
sortArray(score);
//go though the array( in descending order) and check for a place that suits the conditions
while(pos>=0 && score[pos] …Run Code Online (Sandbox Code Playgroud) 我首先要在父节点下返回一组特定的节点,这些节点的id等于1,这非常有效.
IEnumerable<XElement> world1 = LevelData.root.
Elements("world").
Where(element => (int?)element.Attribute("id") == 1);
Run Code Online (Sandbox Code Playgroud)
但我需要多次这样做,每个都有自己的实例,所以我想把它们放入一个列表,但它甚至没有编译告诉我错误CS0266:
无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Collections.Generic.List>'.存在显式转换(您是否错过了演员?)
List<IEnumerable<XElement>>[] World = new List<IEnumerable<XElement>>[noofworlds];
foreach (List<IEnumerable<XElement>> wn in World)
{
Debug.WriteLine("World: "+w);
//this will make a list of all the nodes (elements) within the world specified by the id tag
World[w] = LevelData.Root.Elements("world").Where(element => (int?)element.Attribute("id") == 1);//with id == to i
w++;
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试在List<IEnumerable<XElement>>之前添加演员,LevelData.root.
但后来我得到了一个invalidcastexception.我在哪里可以去砖墙.有什么建议?