using System.Collections.Generic;
public class StockMasterDTO
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public StockMasterDTO(int id, string name, double price)
public override string ToString()
return $"ID: {Id}, Name: {Name}, Price: {Price}";
public static void Main(string[] args)
Dictionary<int, StockMasterDTO> stockDictionary = new Dictionary<int, StockMasterDTO>();
Console.WriteLine($"Initial Dic");
stockDictionary.Add(1, new StockMasterDTO(1, "AAPL", 150.00));
stockDictionary.Add(2, new StockMasterDTO(2, "MSFT", 250.00));
stockDictionary.Add(3, new StockMasterDTO(3, "GOOG", 200.00));
if (stockDictionary.TryGetValue(keyToAccess, out StockMasterDTO stockItem))
Console.WriteLine($"Accessed: {stockItem}");
Console.WriteLine($"Stock item with ID {keyToAccess} not found.");
if (stockDictionary.Remove(keyToRemove))
Console.WriteLine($"Removed stock item with ID {keyToRemove}.");
Console.WriteLine($"Stock item with ID {keyToRemove} not found.");
Console.WriteLine("All stock items in the dictionary:");
foreach (var kvp in stockDictionary)
Console.WriteLine($"Key: {kvp.Key}, Value: {kvp.Value}");