| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 692 人关注过本帖
标题:string to int32的问题
只看楼主 加入收藏
有敌手
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-2-12
收藏
 问题点数:0 回复次数:3 
string to int32的问题
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 小学加减
{
    public partial class Form1 : Form
    {
        int count = 0;

        public Form1()
        {
            InitializeComponent();
        }


        private void button2_Click(object sender, EventArgs e)
        {
            string temp = count.ToString();
            string ab = "你做对了" + temp + "道题";
            MessageBox.Show(ab);
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            int result;
            Random r = new Random();

            int i = r.Next(0, 20);
            int j = r.Next(0, 20);


            
            if (j < 0)
            {
                j = Math.Abs(j);
                string x = Convert.ToString(i);
                string y = Convert.ToString(j);

                textBox1.Text = x + " - " + y;
            }

            else
            {
                string x = i.ToString();
                string y = j.ToString();

                textBox1.Text = x + " + " + y;
            }
            //MessageBox.Show(textBox2.Lines[0]);
            result = Convert.ToInt32(textBox2.Lines[0]);



            if (result  == i + j)
            {
                MessageBox.Show("OK");
                count++;
            }

            textBox2.Clear();



        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Random r = new Random();

            int i = r.Next(0, 20);
            int j = r.Next(0, 20);



            if (j < 0)
            {
                j = Math.Abs(j);
                string x = Convert.ToString(i);
                string y = Convert.ToString(j);
                textBox1.Text = x + " - " + y;
            }

            else
            {
                string x = i.ToString();
                string y = j.ToString();
                textBox1.Text = x + " + " + y;
            }
        }
    }
}

红色的代码始终无法执行,请问是为什么?
搜索更多相关主题的帖子: string 
2008-10-23 22:28
zhutoudd
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-6-24
收藏
得分:0 
你断点设置一下,你看看i+j加完了等于几,和 result  对比一下,应该是逻辑有点毛病吧。
2008-10-23 22:31
ruanjian2110
Rank: 3Rank: 3
来 自:武汉
等 级:论坛游民
威 望:7
帖 子:486
专家分:50
注 册:2008-5-25
收藏
得分:0 
你的if条件不为真,所以程序不运行那里..

武汉信控科技有限公司:http://www. 超越技术,本身就是一个美好技术。。。。。。
2008-10-23 22:32
hqh214
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-1
收藏
得分:0 
textbox.lines[0]是整数值吗???

[[it] 本帖最后由 hqh214 于 2008-10-23 23:02 编辑 [/it]]
2008-10-23 22:56
快速回复:string to int32的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015703 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved