https://github.com/markylaredo/dotnet10-preview
https://github.com/markylaredo/dotnet10-preview
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/markylaredo/dotnet10-preview
- Owner: markylaredo
- Created: 2025-07-10T01:35:54.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-07-10T01:45:53.000Z (11 months ago)
- Last Synced: 2025-07-10T10:36:36.458Z (11 months ago)
- Language: C#
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# .NET 10 Preview: Stock Tickers Example
This project demonstrates different C# record types and their behaviors using stock ticker examples.
## Examples
### 1. Using `DiagramSource`
Demonstrates adding multiple [`Ticker2`](StockTickersExample.cs) instances to a [`DiagramSource`](StockTickersExample.cs) collection.
```csharp
var ds = new DiagramSource(101);
var t1 = new Ticker2("BTC", 60000m);
var t2 = new Ticker2("ETH", 4000m);
var t3 = new Ticker2("DOGE", 0.25m);
ds.Add(t1);
ds.Add(t2, t3);
```
### 2. Using `Ticker1` (Immutable Record Class)
Shows how to use an immutable record class and its `Change` method.
```csharp
var ticker = new Ticker1("FB", 250m);
var updated = ticker.Change(20m);
var furtherUpdated = updated.Change(30m);
```
### 3. Using `Ticker2` (Record Class - Reference Type)
Demonstrates value equality vs reference equality for record classes.
```csharp
var tickerA = new Ticker2("NFLX", 500m);
var tickerB = new Ticker2("NFLX", 500m);
Console.WriteLine(tickerA == tickerB); // True (value equality)
Console.WriteLine(ReferenceEquals(tickerA, tickerB)); // False (reference equality)
```
### 4. Using `Ticker3` (Record Struct - Value Type)
Shows value-type semantics (copying) with record structs.
```csharp
var tOriginal = new Ticker3("SOL", 150m);
var tCopy = tOriginal;
tCopy = new Ticker3(tCopy.Symbol, 200m);
// tOriginal.LastPrice is still 150m, tCopy.LastPrice is 200m
```
## Types
- [`DiagramSource`](StockTickersExample.cs): Holds a collection of [`Ticker2`](StockTickersExample.cs) objects.
- [`Ticker1`](StockTickersExample.cs): Immutable record class (reference type) with a `Change` method.
- [`Ticker2`](StockTickersExample.cs): Record class (reference type), demonstrates value equality.
- [`Ticker3`](StockTickersExample.cs): Record struct (value type), demonstrates value-type copying.
See [StockTickersExample.cs](StockTickersExample.cs) for full code.