English 中文(简体)
i 可以打印文件结果
原标题:i can t print the result in the file
  • 时间:2011-10-08 23:49:42
  •  标签:
  • c#

it hit me an error in this line:foreach(var textBox in textBoxes).it doesn t recognise the:textBoxes.i try to write as TextBox and hits me again an error.i have the Visual C# 2010 Express edition

public Form1()
{
    InitializeComponent();

    private TextBox[] TextBoxes = {textBox1, textBox2, textBox3, textBox4, textBox5, textBox6};

    private List<string> storeItems = new List<string>();
}

private void button1_Click(object sender, EventArgs e)
{
    var buffer = new StringBuilder();
    foreach(var textBox in textBoxes)
    {
        if (string.IsNullOrEmpty(textBox.Text))
        {
            textBox.BackColor = Color.FromName("LightSalmon");
            MessageBox.Show("This item cannot be left blank");
            textBox.Focus();
            return;
        }
        textBox.BackColor = Colors.FromName("Window");
        buffer.Append(textBox.Text);
    }

    var result = buffer.ToString();
    storeItems.Add(result);
    System.IO.File.AppendAllText(@"C:UsersvDesktop	ext.txt", Environment.NewLine + result);
}
最佳回答

它希望你重新努力在建筑商内建造田地。 你们可以这样做,相反:

private TextBox[] TextBoxes = {textBox1, textBox2, textBox3, textBox4, textBox5, textBox6};

private List<string> storeItems = new List<string>();

public Form1()
{
    InitializeComponent();
}

它也认为,资本化是错误的。 <代码>TextBoxes在C#中不同于textBoxes

问题回答

This line is placed in the wrong place.

private TextBox[] TextBoxes = {textBox1, textBox2, textBox3, textBox4, textBox5, textBox6};

Your variable TextBox is recognized only in the constructor. You have to place it in the class, not in a method of the class.

For example after this line:

public partial class Form1 : Form

Or even like this:

public Form1()
{
    InitializeComponent();

    private TextBox[] TextBoxes = {textBox1, textBox2, textBox3, textBox4, textBox5, textBox6};

    private List<string> storeItems = new List<string>();
}
private TextBox[] TextBoxes = {textBox1, textBox2, textBox3, textBox4, textBox5, textBox6};
private void button1_Click(object sender, EventArgs e)
{

Edit: As Svick said, this line too is not in the right place:

private List<string> storeItems = new List<string>();

Follow the same rule for it.

Could it be that your array TextBoxes is capitalized while you re trying to foreach through textBoxes?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签