Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 价值比较不需要';t返回结果_C#_Arrays_Dictionary_Bitmap - Fatal编程技术网

C# 价值比较不需要';t返回结果

C# 价值比较不需要';t返回结果,c#,arrays,dictionary,bitmap,C#,Arrays,Dictionary,Bitmap,我有一门课,有两个数字。开始编号和结束编号,然后将开始编号和结束编号之间的值与保存在字典中的图像进行比较,并将匹配的图像保存到另一个位图数组中以便打印。 例如,输入数字1作为起始数字,输入数字5作为结束数字。 然后,程序将创建一个int数组,该数组保存从1到5的值。即1,2,3,4,5。然后将该数组转换为字符串数组,并将其格式化为5位数字,因为打印时数字必须采用该格式。00001,00002,00003,00004,00005. 但是,为了进行比较,数字必须是单个值,因此我将整个字符串数组附加到

我有一门课,有两个数字。开始编号和结束编号,然后将开始编号和结束编号之间的值与保存在
字典中的图像进行比较,并将匹配的图像保存到另一个
位图
数组中以便打印。 例如,输入数字1作为起始数字,输入数字5作为结束数字。 然后,程序将创建一个
int
数组,该数组保存从1到5的值。即1,2,3,4,5。然后将该数组转换为
字符串
数组,并将其格式化为5位数字,因为打印时数字必须采用该格式。00001,00002,00003,00004,00005. 但是,为了进行比较,数字必须是单个值,因此我将整个字符串数组附加到一个
string
中,然后添加到一个
Char[]
中进行比较。 这是负责整个过程的班级

private Bitmap[] Process()
{
    //Main variables
    int min = Int32.Parse(textBox1.Text);
    int max = Int32.Parse(textBox2.Text);
    List<int> fullVal = new List<int>();
    Boolean converted = false;
    int i;
    //adds the starting number to the array and then increments it by one each time.
    for (int count = 0; count < max;count++)
    {
        fullVal.Add(min);
        min++;
    }

    //converts the new int list to a string array formatted to 5 digits.
    String[] values = new String[fullVal.Count];
    for (int count = 0; count < max;count++)
    {
        values[count] = fullVal[count].ToString("00000");
    }
    //transforms string array into a single string to be converted to char array.
    String complete = null;
    for (int count = 0; count < max; count++)
    {
        complete += values[count];
    }

    //converts string into char array for comparison.
    Char[] indVals = complete.ToCharArray();

    //Dictionary of bitmap images and their respective names.
    Dictionary<String, Bitmap> namesAndImages = new Dictionary<String, Bitmap>();

    var resourceManager = Resource1.ResourceManager;
    var resources = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

    foreach (DictionaryEntry myResource in resources)
    {
        if (myResource.Value is Bitmap) //is this resource is associated with an image
        {
            String resName = myResource.Key.ToString(); //get resource's name

            Bitmap resImage = myResource.Value as Bitmap; //get the Image itself

            namesAndImages.Add(resName, resImage);
        }
    }
    //COMPARISON!! Creates bitmap array to hold the matched images. In this case it holds every image in a sequence
    //for it to be sent to the printer class and printed 5 per page.
    Bitmap[] compare = new Bitmap[values.Length];//array that holds the matched images from pics[]

    while (converted == false)
    {

        for (i = 0; i < max; i++)
        {
            if (namesAndImages.Keys.ElementAt(i).ToCharArray().Contains(indVals[i]))
            {
                compare[i] = new Bitmap(namesAndImages["_0"]);
            }
            else
            {
                switch (indVals[i])
                {
                    case '1': compare[i] = new Bitmap(namesAndImages["_1"]);
                        break;
                    case '2': compare[i] = new Bitmap(namesAndImages["_2"]);
                        break;
                    case '3': compare[i] = new Bitmap(namesAndImages["_3"]);
                        break;
                    case '4': compare[i] = new Bitmap(namesAndImages["_4"]);
                        break;
                    case '5': compare[i] = new Bitmap(namesAndImages["_5"]);
                        break;
                    case '6': compare[i] = new Bitmap(namesAndImages["_6"]);
                        break;
                    case '7': compare[i] = new Bitmap(namesAndImages["_7"]);
                        break;
                    case '8': compare[i] = new Bitmap(namesAndImages["_8"]);
                        break;
                    case '9': compare[i] = new Bitmap(namesAndImages["_9"]);
                        break;

                    default: break;


                }
            }
        }
        converted = true;
    }
    return compare;
}
私有位图[]进程()
{
//主要变量
int min=Int32.Parse(textBox1.Text);
int max=Int32.Parse(textBox2.Text);
List fullVal=新列表();
布尔值=假;
int i;
//将起始数字添加到数组中,然后每次递增一。
对于(int count=0;count

当我调用process类并将调用分配给位图数组时,该数组为空。我无法找出比较或位图分配的错误所在。

你不能“调用类”。请告诉我们你在课堂上做什么。您正在调用
Process()
?您应该做的是在
Process()
方法的第一行上放置一个断点,运行程序,然后使用F10逐步完成代码。您将了解代码实际在做什么。请尝试执行一些调试。为每个步骤使用断点或某种输出。你有一种方法可以做5件事。也许把它分开,测试每个部分。显然,如果资源查找失败或数字分配不正确,位图分配将失败(当您将值放入“fullVal”时,我已经看到一个问题)。另外,使用参数。您的循环都假设
min
为1。你应该为我做
(int num=min;num也用于从数组或字符串列表中创建一个
string
,您可以使用
string.Join
string.Concat
。最后,您将执行从0到
max
的循环,但在char数组中使用它完全没有意义,因为在零填充的c中会有更多的字符与
max
不同的字符串。