Global type aliases in C#

Viewed 3440

let me start right away with the code:

class Item {
    public int highestBuyOffer;
    public int lowestSellOffer;
    [...]
}

I would like to prevent people using this class from accidently assigning a buy offer value to a sell offer value and the other way round (like someBuyOffer = someSellOffer). That's why I want to create my own types:

class Item {
    public BuyOffer highestBuyOffer;
    public SellOffer lowestSellOffer;
    [...]
}

Creating a struct for it seems overkill, as these both of values should behave exactly like an int.

The using directive is not what I want because:

  1. It is only valid for one file
  2. It does not count as a type, it's just a synonym
1 Answers
Related