char到字符串错误 [英] char to string error

查看:167
本文介绍了char到字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前只有两个错误,从一个工作程序。我将发布包含错误的行和其变量的定义,最后错误。请告诉我在哪里错了。谢谢。

I'm currently just 2 errors away from a working program. I'll post the line that contains error and the definition of its variable and finally the errors. Please tell me where i got wrong. Thank you.

    private Dictionary<string, bool[]> letterData = new Dictionary<string, bool[]>();


    public char[] mapNeurons()
    {
        char[] map = new char[this.letters.Items.Count];

        for (int i = 0; i < map.Length; i++)
        {
            map[i] = '?';
        }
        for (int i = 0; i < this.letters.Items.Count; i++)
        {
            double[] input = new double[Form1.DOWNSAMPLE_HEIGHT * Form1.DOWNSAMPLE_WIDTH];
            char ch = ((string)(this.letters.Items[i]))[0];
            bool[] data = this.letterData[ch]; //line contains errors
            for (int j = 0; j < input.Length; j++)
            {
                input[j] = data[j] ? 0.5 : -0.5;
            }

            int best = this.network.Winner(input);
            map[best] = ch;
        }
        return map;
    }

这里是错误

错误1System.Collections.Generic.Dictionary.this [string]的最佳重载方法匹配具有一些无效参数

Error 1 The best overloaded method match for 'System.Collections.Generic.Dictionary.this[string]' has some invalid arguments

错误2参数'1 ':不能从'char'转换为'string'

Error 2 Argument '1': cannot convert from 'char' to 'string'

我使用Char而不是String,因为如果使用String,它会返回字符串的整行,要返回字符串的第一个字母

I used Char instead of String because if using String it will return the whole line of the string loaded, i just wants to return the first letter of the string

例如:data = A1:000001100000000110000000111000000011100000001

for example: data = A1:000001100000000110000000111000000011100000001

它会返回整行,我只是想要返回'A'

if use string it will return the whole line, i just wants it to return 'A'

新的识别问题:
当我输入数据,我把数据'A1'键,这解释了为什么im使用字符串,所以当它没有找到'A1',因为它是字符,它只是发现'A'这是为什么它返回'?',是可能的,如果我使用字符串n只是读取第一个字符在字符串行中是'A'?

NEW IDENTIFIED PROBLEM: when i enter the data, i put the data into 'A1' key, which explain why im using string, so when it didnt find 'A1' because it is char, it just find 'A' thats why it returned '?', is it possible if i use string n just read the first character which is 'A' in the string line?

推荐答案

要将字符转换为字符串, ToString ()可以调用。这是问题的解决方案。

To convert char to string, ToString() can be called. This is the solution for the question.

但hafizhans,正在处理一些程序,他曾问过问题,其中他将 Dictionary< char,bool []> 字典< string,bool []> 。现在他正在将这些数据从字典存储到文本文件中。

But hafizhans, was working on some program, for which he had asked question, where he converted the Dictionary<char, bool[]> to Dictionary<string, bool[]>. Now he was storing the data from dictionary to text file something like this

A1:001110000111100001010100

现在读这篇文章时,他只需要 A1 > Split 函数做了。
>

Now while reading this, he only needed A1 part, so Split function did the trick.

这篇关于char到字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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