Распределение уровня доступа переменных - C#
Формулировка задачи:
Необходимо с помощью FolderBrowserDialog выбрать директорию с файлами, а затем записать все имена файлов данной директории в массив. Есть следующий код
Но переменную directFiles нигде не видно, кроме public void button4_Click(object sender, EventArgs e).
Как расширить её уровень доступа?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string att;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < directFiles.Length; i++)
{
XmlTextReader reader = new XmlTextReader(directFiles[i]);
while (reader.Read())
{
textBox2.Text += reader.GetAttribute("status");
}
att = textBox2.Text;
textBox1.Text += directFiles[i] + " Количество Status = " + att.Length + "\r\n\r\n";
textBox2.Clear();
att = "";
}
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < directFiles.Length; i++)
textBox1.Text += directFiles[i] + "\r\n\r\n";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
public void button4_Click(object sender, EventArgs e)
{
FolderBrowserDialog FBD = new FolderBrowserDialog();
string[] directFiles = Directory.GetFiles(FBD.SelectedPath);
if (FBD.ShowDialog() == DialogResult.OK)
{
textBox2.Text = FBD.SelectedPath;
}
}
}
}Решение задачи: «Распределение уровня доступа переменных»
textual
Листинг программы
public partial class Form1 : Form
{
string att;
string [] directFiles;
public Form1()
{
InitializeComponent();
}
public void button4_Click(object sender, EventArgs e)
{
FolderBrowserDialog FBD = new FolderBrowserDialog();
directFiles = Directory.GetFiles(FBD.SelectedPath);
//...