Using static

C# 6.0 introduces a new kind of using statement that now refers to types instead of namespaces. This means that the static members of the type are then directly put into scope. What this means for your code is evident in the condensed result of this recipe.

Getting ready

We will create a class called Recipe7UsingStatic that will determine the sale price of an item depending on the day of the week. If it is Friday, we want to apply the sale discount to the item. On any other day, we will sell the item at the shelf price.

How to do it…

  1. Start by creating a Recipe7UsingStatic class that contains two auto-implemented properties and an enumerator for the day of the week:
    public static class Recipe7UsingStatic { public enum TheDayOfWeek { Monday, ...

Get C# Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.