https://github.com/jonasraoni/csharp-variant-type
A class that mimics the behavior of the so-called variant data type.
https://github.com/jonasraoni/csharp-variant-type
csharp data-type datatype type variant-data variants
Last synced: 7 months ago
JSON representation
A class that mimics the behavior of the so-called variant data type.
- Host: GitHub
- URL: https://github.com/jonasraoni/csharp-variant-type
- Owner: jonasraoni
- License: mit
- Created: 2017-11-01T22:14:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-01T23:57:09.000Z (over 8 years ago)
- Last Synced: 2025-06-25T05:43:12.854Z (8 months ago)
- Topics: csharp, data-type, datatype, type, variant-data, variants
- Language: C#
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C# Variant data type
A class that mimics the behavior of the so-called variant data type.
The Variant class can be transparently assigned and converted to/from any basic data type (string, datetime, sbyte, byte, short, int, long, ushort, uint, ulong, float, double, bool, char, decimal as well as their nullable types).
See the file [test.cs](test.cs) to view the possibilities.
```csharp
var v = new Variant(123);
Variant v2 = 0;
Console.WriteLine(v == v2);
Console.WriteLine(v > v2);
Console.WriteLine(v2 ? "v2 converted to true" : "v2 converted to false");
Console.WriteLine((int)v);
Console.WriteLine((bool)v);
Console.WriteLine((double)v);
Console.WriteLine(((int?)new Variant(null)).HasValue);
Console.WriteLine(((DateTime)new Variant(DateTime.Now)).ToString("o"));
Console.WriteLine((bool)new Variant("False"));
Console.WriteLine((float)new Variant("123.321"));
```