Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Newtonsoft.Json;
- namespace Json.NET_tests
- {
- public class Can
- {
- public enum Brand
- {
- CocaCola = 0,
- Pepsi = 1,
- DrPepper = 2
- };
- public Brand brand;
- public float price;
- public string flavour;
- }
- class Program
- {
- static void Main(string[] args) {
- Can[] cans = new Can[100];
- for(int i = 0; i < cans.Length; i++)
- {
- Random rnd = new Random(i);
- Can temp = new Can();
- temp.brand = (Can.Brand)rnd.Next(0, 4);
- temp.price = ((float)rnd.Next(50, 151)) / 100f;
- switch(rnd.Next(0, 4))
- {
- case 0:
- temp.flavour = "Cola";
- break;
- case 1:
- temp.flavour = "Lemon";
- break;
- case 2:
- temp.flavour = "Ass";
- break;
- case 3:
- temp.flavour = "Coffee";
- break;
- }
- cans[i] = temp;
- }
- String ser = JsonConvert.SerializeObject(cans);
- Console.Write(ser);
- Console.ReadLine();
- Can[] cans2 = JsonConvert.DeserializeObject<Can[]>(ser);
- for (int i = 0; i < cans.Length; i++)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Can number" + (i+1) + ":");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(cans2[i].brand);
- Console.WriteLine(cans2[i].price);
- Console.WriteLine(cans2[i].flavour);
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement