Как передать var в другой класс
Переменную var нельзя сделать публичной, а это значит ее нельзя вызвать в другом классе.
У меня 2 класса, в одном есть переменная var, а в другом нужно к ней обратиться, как поступить?
private void Button_Click_8(object sender, RoutedEventArgs e)
{
dg2.ItemsSource = me.ToList();
}
class ExcelImportSheet
{
internal class Metric
{
public int IDОбращения { get; set; }
public string IdКлиента { get; set; }
public string ФИО { get; set; }
public string Email { get; set; }
public string Услуга { get; set; }
public string Статус { get; set; }
public string ОценкаКлиента { get; set; }
}
public IEnumerable<Metric> EnumerateMetrics(string xlsxpath)
{
var openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel Files|*.xls;*.xlsx";
if (openFileDialog.ShowDialog() == true)
{
var excelFilePath = openFileDialog.FileName;
}
using (var excelFilePath = new XLWorkbook(xlsxpath))
using (var worksheet = excelFilePath.Worksheets.Worksheet(1))
{
for (int row = 2; row <= 10; ++row)
{
var me = new Metric
{
IDОбращения = excelFilePath.Cell("A5:A100").GetValue<int>(),
IdКлиента = excelFilePath.Cell("B5:B100").GetValue<string>(),
ФИО = excelFilePath.Cell("C5:C100").GetValue<string>(),
Email = excelFilePath.Cell("D5:D100").GetValue<string>(),
Услуга = excelFilePath.Cell("E5:E100").GetValue<string>(),
Статус = excelFilePath.Cell("F5:F100").GetValue<string>(),
ОценкаКлиента = excelFilePath.Cell("G5:G100").GetValue<string>(),
};
yield return me;
}
}
}
}