-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.WriteAllText01.cs
More file actions
48 lines (48 loc) · 1.66 KB
/
File.WriteAllText01.cs
File metadata and controls
48 lines (48 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace SimpleMethod
{
internal class Program
{
static void Main(string[] args)
{
Computer.Models.Computer myComputer = new Computer.Models.Computer()
{
Motherboard = "Z1255",
CPUCores = 4,
HasWifi = true,
HasLTE = false,
Price = 0,
ReleaseDate = DateTime.Now,
VideoCard = "RTX 2060"
};
string sql = "\n" + @"INSERT INTO TutorialAppSchema.Computer (
Motherboard,
CPUCores,
HasWifi,
HasLTE,
ReleaseDate,
Price,
VideoCard
) VALUES ('" + myComputer.ComputerId
+ "','" + myComputer.CPUCores
+ "','" + myComputer.CPUCores
+ "','" + myComputer.HasWifi
+ "','" + myComputer.HasLTE
+ "','" + myComputer.ReleaseDate
+ "','" + myComputer.Price
+ "','" + myComputer.VideoCard
+ "')\n";
//Version 1
File.WriteAllText("..\\..\\..\\log.txt", sql);
//Version 2
File.WriteAllText("..\\..\\..\\log.txt", "\n" + sql + "\n");
//Version 3
using StreamWriter openFile = new("..\\..\\..\\log.txt", append: true);
openFile.WriteLine(sql);
openFile.Close();
//Save as variable
string fileText = File.ReadAllText("..\\..\\..\\log.txt");
//Read the file
Console.WriteLine(fileText);
}
}
}