Skip to content

Instantly share code, notes, and snippets.

@sampritipanda
Created April 18, 2015 20:27
Show Gist options
  • Save sampritipanda/ba6917c2297f1d322004 to your computer and use it in GitHub Desktop.
Save sampritipanda/ba6917c2297f1d322004 to your computer and use it in GitHub Desktop.
Structs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Structs
{
public struct Menu
{
private Coffee[] coffees;
public Menu(string name)
{
Coffee coffee1 = new Coffee(name, 0);
coffees = new Coffee[1] { coffee1 };
}
public Coffee this[int index]
{
get { return this.coffees[index]; }
set { this.coffees[index] = value; }
}
}
public struct Coffee
{
public Coffee(string name, decimal price)
{
this.Name = name;
this.Price = price;
}
public string Name { get; set; }
public decimal Price { get; set; }
}
class Program
{
static void Main(string[] args)
{
Menu menu1 = new Menu("Starbucks");
Console.WriteLine(menu1[0].Name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment