-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cs
More file actions
50 lines (40 loc) · 1.6 KB
/
Copy pathExample.cs
File metadata and controls
50 lines (40 loc) · 1.6 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
49
50
using System;
using System.Collections.Generic;
using System.Text.Json;
using ModelingEvolution;
// Example usage of ModelingEvolution.Bytes
// Create from various sources
Bytes size1 = 1024; // From int
Bytes size2 = 1048576u; // From uint
Bytes size3 = 1099511627776L; // From long
Bytes size4 = "2.5GB"; // From string with parsing
Console.WriteLine($"Size 1: {size1}"); // "1.0 KB"
Console.WriteLine($"Size 2: {size2}"); // "1.0 MB"
Console.WriteLine($"Size 3: {size3}"); // "1.0 TB"
Console.WriteLine($"Size 4: {size4}"); // "2.5 GB"
// Arithmetic operations
var total = size1 + size2;
Console.WriteLine($"Total: {total}"); // "1.0 MB"
// Comparisons
if (size1 < size2)
Console.WriteLine("Size1 is smaller than Size2");
// Use as dictionary keys (JSON serializable)
var fileSizes = new Dictionary<Bytes, string>
{
[Bytes.Parse("100MB")] = "video.mp4",
[Bytes.Parse("5KB")] = "config.json",
[Bytes.Parse("2GB")] = "database.db"
};
// Serialize to JSON
var json = JsonSerializer.Serialize(fileSizes);
Console.WriteLine($"JSON: {json}");
// The struct is readonly - all operations create new instances
var original = new Bytes(1024);
var doubled = original * 2;
Console.WriteLine($"Original: {original}, Doubled: {doubled}");
// Implicit conversions work seamlessly
int intValue = new Bytes(2048);
uint uintValue = new Bytes(4096);
long longValue = new Bytes(8192);
ulong ulongValue = new Bytes(16384);
Console.WriteLine($"Converted values: {intValue}, {uintValue}, {longValue}, {ulongValue}");