DEV Community

Ramkumar Radhakrishnan
Ramkumar Radhakrishnan

Posted on

Senior C#/.NET Developer Learning Plan. Day - 01.

Senior C#/.NET Developer Learning Plan
Duration: 12 Weeks (60 Sessions) | Daily Commitment: 1 Hour | Schedule: Monday to Friday

Day - 01

Topics - C# 10-12 Features

  1. Global Using Directives *Explanation *- This feature allows you to declare common namespaces globally, eliminating the need to add using statements in every file.

Real-world use: In large projects, many files might use the same set of namespaces (e.g., System, System.Collections.Generic, System.Linq). Global usings can significantly reduce the boilerplate code at the top of each file, making code cleaner and more readable.

Code Samples.

GlobalUsing.cs

global using System;
global using System.Collections.Generic;
global using System.Linq;
Enter fullscreen mode Exit fullscreen mode

Program.cs

public class Product
{
    public string Name { get; set; }
    public decimal Price { get; set; }
}

public class Order
{
    public List<Product> Products { get; set; } = new();

    public decimal TotalPrice => Products.Sum(p => p.Price);
    public void AddProduct(Product product)
    {
        Products.Add(product);
    }

    public void RemoveProduct(Product product)
    {
        Products.Remove(product);
    }

    public void ClearProducts()
    {
        Products.Clear();
    }

    public override string ToString()
    {
        return $"Order with {Products.Count} products, Total Price: {TotalPrice:C}";
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        Order order = new();
        order.AddProduct(new Product { Name = "Apple", Price = 1.20m });
        order.AddProduct(new Product { Name = "Banana", Price = 0.80m });
        Console.WriteLine(order.ToString());
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)