我需要得到的產品代碼,價格和庫存對包含如何閱讀和TXT一條線寫特定字在C#控制檯
//product code;product name;price;stock;
c01;cappuccino;3500;12;
c02;mocaccino;4000;15;
c03;black coffe;3000;10;
c04;chocolate milk;5000;19;
c05;vanilla milk;5000;12;
c06;strawberry milk;5000;13;
c07;coke;3000;13;
c08;fanta;3000;15;
c09;sprite;3000;9;
c10;orange juice;4500;10;
c11;apple juice;4500;9;
c12;mango juice;4500;18;
我試過
txt文件計算if(line.Contains(""))
但行在line.contains給錯誤紅色下劃線,而我缺少使用命名空間爲此?
也是我試過
FileStream fs = new FileStream("product.txt", FileMode.OpenOrCreate, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str = sr.ReadLine();
while (str != null)
{
Console.WriteLine("{0}", str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();
的做法得到一個字,但它從TXT代替
_ 「但在line.contains行給出錯誤紅色下劃線代替,我失去了使用......」 _ - ** Pro Tip **:如果將鼠標移動到紅色下劃線/扭曲處並將鼠標懸停在那裏一會兒,Visual Studio將顯示一個工具提示,描述問題 – MickyD