'minValue'不能大于maxValue错误。 [英] 'minValue' cannot be greater than maxValue error.

查看:1334
本文介绍了'minValue'不能大于maxValue错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试读取文本文件(Words.txt),然后从Words.txt文件中选择一个单词。



但是我现在收到的'minValue'不能大于maxValue错误。



任何人都可以帮助我做错了什么?



我的WordListHelper类:



公共类WordListHelper 
{

private readonly List< string> _wordList = new List< string>();

private async void ProjectFile()
{
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
_Folder = await _Folder.GetFolderAsync(Hangman);

//获取文件

StorageFolder sf = KnownFolders.DocumentsLibrary;
StorageFile file = await sf.GetFileAsync(Words.txt);
string _wordList = await FileIO.ReadTextAsync(file);
}

公共字符串Getword()
{
随机r = new Random();

int i = r.Next(0,_wordList.Count - 1);

返回_wordList.ElementAt(i);
}

}
}





引发错误的代码行:

 int i = r.Next(0,_wordList.Count  -  1); 





问候,



Glen。

解决方案

似乎_wordList是空的,所以_wordList.Count - 1 = -1



首先来自_wordList在您的类级别声明,您不应在ProjectFile()方法中使用类型作为前缀:

  private   async   void  ProjectFile()
{
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
_Folder = await _Folder.GetFolderAsync( 刽子手);

// 获取文件

StorageFolder sf = KnownFolders.DocumentsLibrary;
StorageFile file = await sf.GetFileAsync( Words.txt);
string result = await FileIO.ReadTextAsync(file);
_wordList.Add(result);
}





然后你应该在尝试在你的GetWord中使用它之前检查_wordList的内容( )方法:

  public   string  Getword ()
{
Random r = new Random();
int i = -1;
if (_ wordList.Count > 0 ){
i = r.Next( 0 ,_ wordList.Count - 1 );
}
返回(i > -1)? _wordList.ElementAt(i): string .Empty;
}





希望这有帮助。


看起来像< b> _wordList.Count 等于零。

您确定 _wordlist 充满了拨打 GetWord()所需的所有数据吗?

Hello,

I am trying to read in a text file (Words.txt) and then select a word out from the "Words.txt" file.

However I am now receiving a 'minValue' cannot be greater than maxValue error.

Can anyone help me with what I may have done wrong?

My WordListHelper class:

public class WordListHelper
    {

        private readonly List<string> _wordList = new List<string>();        

        private async void ProjectFile()
        {            
                var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                _Folder = await _Folder.GetFolderAsync("Hangman");
 
                // acquire file
            
                StorageFolder sf = KnownFolders.DocumentsLibrary;
                StorageFile file = await sf.GetFileAsync("Words.txt");
                string _wordList = await FileIO.ReadTextAsync(file);            
        }

        public string Getword()
        {
            Random r = new Random();

            int i = r.Next(0, _wordList.Count - 1);

            return _wordList.ElementAt(i);
        }

    }
}



Line of code that is throwing the error:

int i = r.Next(0, _wordList.Count - 1);



Regards,

Glen.

解决方案

It seems _wordList is empty, so _wordList.Count - 1 = -1

First of all since _wordList is declared at your class level you should not prefix its use with type in the ProjectFile() method:

private async void ProjectFile()
{
        var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
        _Folder = await _Folder.GetFolderAsync("Hangman");

        // acquire file

        StorageFolder sf = KnownFolders.DocumentsLibrary;
        StorageFile file = await sf.GetFileAsync("Words.txt");
        string result = await FileIO.ReadTextAsync(file);
        _wordList.Add(result);
}



Then you should check for the content of _wordList before trying to use it in your GetWord() method:

public string Getword()
{
    Random r = new Random();
    int i = -1;
    if (_wordList.Count > 0) {
       i = r.Next(0, _wordList.Count - 1);
    }
    return (i > -1) ? _wordList.ElementAt(i) : string.Empty;
}



Hope this helps.


Looks like _wordList.Count equals zero.
Are you sure that _wordlist is filled with all the data needed when you call GetWord()?


这篇关于'minValue'不能大于maxValue错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆