我正在尝试编写一种可在 winform 和控制台中使用的方法。
这是我的代码:
public class BeerKoozie
{
public bool IsSinging = false;
//Your classes aren't working because you didn't have a constructor method.
public BeerKoozie()
{
for (int beerCount = 0; beerCount < 100; beerCount++)
{
beerCollection[beerCount] = new Beer();
if (beerCount == 99)
{
IsSinging = true;
}
}
}
//needs a collection representing one hundred beers.
Beer[] beerCollection = new Beer[100];
// needs a notion of a current beer
public int CurrentBeer = 99;
// needs a notion of going to the next beer.
public string DrinkAbeerAndSingTheSong()
{
//BeerKoozie.bee
//foreach (Beer value in beerCollection)
//foreach (Beer value in beerCollection)
do(Beer i in beerCollection)
{
beerCollection[CurrentBeer].IsFull = false;
CurrentBeer--;
} while (CurrentBeer > 0);
return CurrentBeer.ToString() + "... beers on the wall";
}
每当我尝试在最后打印beerCollection[CurrentBeer]
出来时.ToString
,方法的名称就会打印出来。那么,对于迭代整个数组,同时保持业务端和视图分离的平台无关方法,应该使用哪种模式呢?我可以轻松地编写一个仅适用于控制台或 winform 的方法,并使用其特定的字符串。 (我的代码不可编译,因为我在弄乱该方法时破坏了它,并且无法将其恢复到以前的状态。我现在也有功能齐全的代码,因此无法重现该问题。)