Skip to content

Commit d201b69

Browse files
committed
Add project files.
1 parent 547dd89 commit d201b69

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

Program.cs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace test
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
cell[] board2 = new cell[256];
12+
13+
for (int i = 0; i < board2.Length; ++i)
14+
{
15+
board2[i] = new cell();
16+
board2[i].life = 0;
17+
board2[i].color = "#FF0000";
18+
}
19+
/*
20+
foreach (cell i in board2)
21+
{
22+
Console.WriteLine(i.life);
23+
Console.WriteLine(i.color);
24+
}
25+
*/
26+
27+
board2[245].life = 1;
28+
29+
string jsonString;
30+
jsonString = JsonSerializer.Serialize(board2);
31+
Console.WriteLine(jsonString);
32+
33+
34+
cell[] board = new cell[256];
35+
36+
for (int i = 0; i < board2.Length; ++i)
37+
{
38+
board[i] = new cell();
39+
}
40+
41+
int count = 0;
42+
43+
using (JsonDocument document = JsonDocument.Parse(jsonString))
44+
{
45+
JsonElement root = document.RootElement;
46+
//JsonElement studentsElement = root.GetProperty("Students");
47+
foreach (JsonElement cell in root.EnumerateArray())
48+
{
49+
cell.TryGetProperty("life", out JsonElement lifeElement);
50+
board[count].life = lifeElement.GetInt32();
51+
//Console.WriteLine(lifeElement.ToString());
52+
cell.TryGetProperty("color", out JsonElement colorElement);
53+
board[count].color = colorElement.ToString();
54+
//Console.WriteLine(colorElement.ToString());
55+
count++;
56+
}
57+
}
58+
59+
foreach (cell i in board)
60+
{
61+
Console.WriteLine(i.life);
62+
Console.WriteLine(i.color);
63+
}
64+
65+
66+
}
67+
}
68+
class cell
69+
{
70+
public int life { get; set; }
71+
public string color { get; set; }
72+
}
73+
74+
75+
76+
77+
}

test.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

test.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29806.167
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test.csproj", "{550FD126-6F8F-40D1-8CB7-A3C1ABEB937E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{550FD126-6F8F-40D1-8CB7-A3C1ABEB937E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{550FD126-6F8F-40D1-8CB7-A3C1ABEB937E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{550FD126-6F8F-40D1-8CB7-A3C1ABEB937E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{550FD126-6F8F-40D1-8CB7-A3C1ABEB937E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B7BEE767-927A-4517-878C-7A42CCE8BB2D}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)