⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 模拟校验和计算程序。即输入一段文字
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace wg011
{
    public partial class Form1 : Form
    {
        public StreamReader sr1;
        public char[] str;
        public string buffer;
        public int top;
        public long total;
        public int count,po;
        public Form1()
        {
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            total = 0;
            count = 0;
            po = 0;
            str = new char[100];
            InitializeComponent();
        }
        public int compute()
        {
            count = buffer[po];
            po += 1;
            char t = '\0';
            if (po == top)
            {
                t = '\0';
            }
            else
            {
                t = buffer[po];
                po += 1;
            }
            count *= 256;
            count += t;
            return count;
        }
        private void openb_Click(object sender, EventArgs e)
        {
            string filename1;
            total = 0;
            count = 0;
            po = 0;
            openFileDialog1.Filter = "Text Document(*.txt)|*.txt|All Files|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filename1 = openFileDialog1.FileName;
                try
                {
                    sr1 = new StreamReader(filename1);
                    buffer = sr1.ReadToEnd();
                    top = buffer.Length;
                    while (po != top)
                    {
                        total += compute();
                        if (total > 65535)
                        {
                            total = ((int)total) % 65536 + 1;
                        }
                    }

                }
                catch (Exception E2)
                {
                    MessageBox.Show(E2.Message);
                }
                finally 
                {
                    string temp = Convert.ToString(total, 16);
                    tb1.Text = buffer + " = " + temp;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -