テキストファイルを読み込んで、特定店舗の行のみ出力する。
:Program.cs
using System;
using System.IO;
using System.Text;
namespace List094
{
class Program
{
static void Main(string[] args)
{
// var filePath = @"C:\Example\Greeting";
string filePath = "Sales.txt";
string[] lines = File.ReadAllLines(filePath,Encoding.UTF8);
foreach(var line in lines){
string[] items = line.Split(',');
Sale sale =new Sale{
ShopName = items[0],
Product =items[1],
Amount =int.Parse(items[2])
};
if(sale.ShopName=="浅草店")
Console.WriteLine("{0} {1} {2}",sale.ShopName,sale.Product,sale.Amount);
}
}
}
}
クラス
:Sales.cs
using System;
namespace List094 {
public class Sale{
public String ShopName { get; set; }
public String Product { get; set; }
public int Amount { get; set; }
}
}