Как передать ссылку на файл в метод класса
public Form1()
{
InitializeComponent();
Start();
string path = @"C:\SomeDir";
string subpath = @"program\avalon";
DirectoryInfo dirInfo = new DirectoryInfo(path);
if (!dirInfo.Exists)
{
dirInfo.Create();
}
dirInfo.CreateSubdirectory(subpath);
}
public class Person
{
public string FullName { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
public DateTime Date { get; set; }
public Person(string fullName, int age, string sex, DateTime date)
{
FullName = fullName;
Age = age;
Gender = sex;
Date = date;
}
public Person()
{
}
public virtual void Find()
{
string a = FullName + Age + "\n" + Gender + "\n" + Date;
string b = "Людину яку ви шукаєте";
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(a, b);
}
//MessageBox.Show(a, b);
}
}
Тут нужно чтобы метод Find вместо MassageBox записал значения в файл C:\SomeDir\program\avalon
//Исправил
public virtual void Find(string path)
{
string a = FullName + Age + "\n" + Gender + "\n" + Date;
string b = "Людину яку ви шукаєте";
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(a, b);
}
//MessageBox.Show(a, b);
}
Источник: Stack Overflow на русском