using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 装箱和拆箱
{
class Program
{
static void Main(string[] args)
{
Storehouse store = new Storehouse(5);
store.Add(100);
store.Add(3.14);
store.Add("good");
store.Add(new Storehouse(5));
foreach (object item in store.Items)
{
Console.WriteLine(item);
}
}
}
class Storehouse
{
public Object[] Items;
public int count;
public Storehouse(int size)
{
Items = new object[size];
count = 0;
}
public void Add(object obj)
{
if (count < Items.Length)
{
Items[count] = obj;
count++;
}
else
{
Console.WriteLine("仓库已满!");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 装箱和拆箱
{
class Program
{
static void Main(string[] args)
{
Storehouse store = new Storehouse(5);
store.Add(100);
store.Add(3.14);
store.Add("good");
store.Add(new Storehouse(5));
foreach (object item in store.Items)
{
Console.WriteLine(item);
}
}
}
class Storehouse
{
public Object[] Items;
public int count;
public Storehouse(int size)
{
Items = new object[size];
count = 0;
}
public void Add(object obj)
{
if (count < Items.Length)
{
Items[count] = obj;
count++;
}
else
{
Console.WriteLine("仓库已满!");
}
}
}
}