索引超出了数组的范围[重复]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了索引超出了数组的范围[重复]相关的知识,希望对你有一定的参考价值。
这个问题在这里已有答案:
首先,我不知道哪一个超出了规模。正如你所看到的,我已经把%放在了数组之外。这是我的代码,请不要因为任何幼稚的错误而责备我。如果您有关于更有效的加密方法的提示,我会打开
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace encrypting
public partial class Form1 : Form
string text;
string key;
public string calcXor(string a, string b)
char[] charAArray = a.ToCharArray();
char[] charBArray = b.ToCharArray();
char[] result = new char[6];
int len = 0;
for (int i = 0; i < a.Length; i++)
if (i != 0)
result[i] = (char) ( ((int)charAArray[a.Length % i] ^ (int)charBArray[b.Length % i]) ) ; //error
return new string(result);
private void Crypt()
char[] a;
int i, sizeoftext = text.Length,j=0;
string somestring ="";
string key = textBox2.Text;
StringBuilder sb = new StringBuilder(somestring);
for(i=0;i<sizeoftext-1;i++)
if (i == key.Length-1)
j = 0;
somestring = calcXor(text, key);
if (File.Exists(textBox3.Text)) ;
File.Create(textBox3.Text).Close();
System.IO.File.WriteAllText(textBox3.Text, somestring);
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
private void label1_Click(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
text = File.ReadAllText(textBox1.Text);
Crypt();
private void textBox1_TextChanged(object sender, EventArgs e)
key = this.Text;
private void button2_Click(object sender, EventArgs e)
OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
textBox1.Text = fd.FileName;
private void textBox2_TextChanged(object sender, EventArgs e)
private void label2_Click(object sender, EventArgs e)
private void button3_Click(object sender, EventArgs e)
FolderBrowserDialog fd = new FolderBrowserDialog();
if(fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
textBox3.Text = fd.SelectedPath;
textBox3.Text = textBox3.Text +"\\" + textBox4.Text + ".txt";
private void textBox4_TextChanged(object sender, EventArgs e)
private void textBox3_TextChanged(object sender, EventArgs e)
请帮我。
答案
如果您的字符串超过6个字符,则以下任务将超出范围:result[i] = (char) ( ((int)charAArray[a.Length % i] ^ (int)charBArray[b.Length % i]) )
; //错误
以上是关于索引超出了数组的范围[重复]的主要内容,如果未能解决你的问题,请参考以下文章