本文整理汇总了C#中Bag类的典型用法代码示例。如果您正苦于以下问题:C# Bag类的具体用法?C# Bag怎么用?C# Bag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bag类属于命名空间,在下文中一共展示了Bag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_not_return_ticket_given_full_cabinet_when_pick
public void should_not_return_ticket_given_full_cabinet_when_pick()
{
Bag bag = new Bag();
var cabinet = new Cabinet(0);
Assert.IsNull(new Direct(cabinet).Store(bag));
}
示例2: Store
public Ticket Store(Bag aBag, Ticket ticket)
{
if (!HasEmptyBox()) return null;
_dicTicketBag.Add(ticket, aBag);
return ticket;
}
示例3: Simple
public void Simple()
{
var bag1 = new Bag<string>();
var bag2 = GetTestBag();
var resultBag = bag1 * bag2;
Assert.IsTrue(resultBag.Equals(bag1));
bag1.Add("50", 2);
var shouldBe = new Bag<string>();
resultBag = bag1 * bag2;
Assert.IsTrue(shouldBe.Equals(resultBag));
bag1.Add("2", 2);
shouldBe.Add("2", 2);
resultBag = bag1 * bag2;
Assert.IsTrue(shouldBe.Equals(resultBag));
}
示例4: Store_One_Bag_When_Not_All_Cabinets_Full_Return_Ticket
public void Store_One_Bag_When_Not_All_Cabinets_Full_Return_Ticket()
{
var smartRobot = new SmartRobot(new List<Cabinet> { new Cabinet(0), new Cabinet(1), new Cabinet(0) });
var bag = new Bag();
var ticket = smartRobot.Store(bag);
Assert.IsNotNull(ticket);
}
示例5: Interface
public void Interface()
{
var bag1 = new Bag<int> { 3, 4, 5, 6 };
var bag2 = new Bag<int> { 3, 4, 5 };
var shouldBe = new Bag<int> { 6 };
var resultBag = (Bag<int>)((IBag<int>)bag1).Subtract(bag2);
Assert.IsTrue(resultBag.Equals(shouldBe));
bag1.Clear();
bag2.Clear();
bag1.Add(3, 3);
bag2.Add(3, 2);
bag1.Add(5, 5);
bag2.Add(5, 7);
shouldBe.Clear();
shouldBe.Add(3, 1);
resultBag = bag1.Subtract(bag2);
Assert.IsTrue(resultBag.Equals(shouldBe));
}
示例6: TestAddRange
public void TestAddRange()
{
Bag<string> target = new Bag<string>(Capacity);
Bag<string> rangeOfElements = new Bag<string>(Capacity) { TestElement1, TestElement2, TestElement3 };
target.AddRange(rangeOfElements);
Assert.IsTrue(target.Contains(TestElement1) && target.Contains(TestElement2) && target.Contains(TestElement3));
}
示例7: ReadElement
private void ReadElement(XmlReader reader, Bag parent) {
var name = XmlConvert.DecodeName(reader.LocalName);
var type = reader["type"];
// is it a value node ? i.e. type=""
if (type != null) {
if (type == "Array") {
// go to first item
parent.SetMember(name, ReadArray(reader));
reader.Read();
}
else {
var typeCode = (TypeCode)Enum.Parse(typeof(TypeCode), type);
var value = SConvert.XmlDecode(typeCode, reader.ReadElementString());
parent.SetMember(name, value);
}
}
else {
var grappe = new Bag();
reader.Read();
parent.SetMember(name, grappe);
while (reader.MoveToContent() == XmlNodeType.Element) {
ReadElement(reader, grappe);
}
reader.Read();
}
}
示例8: Dikabryozik
public Dikabryozik(Point position)
{
IsPassable = false;
Size = new Size(1, 1);
Id = 0x00018000;
Speed = 10;
ViewRadius = 3;
ViewSight = new Size((uint)ViewRadius, (uint)ViewRadius);
Position = position;
_bundle = new Bag(2, 2);
ObjectWithState = new ObjectWithState(
new List<IObjectState>
{
new Staying() {TickCount = STAYING_BASE_TICKCOUNT, Distribution = STAYING_BASE_TICKCOUNT/10, Eternal = false},
new Hungry() {TickCount = 300, Distribution = 30, Eternal = true}
},
false, null, OnChangeState);
this.StateEvent.FireEvent();
}
示例9: Main
public static void Main(string[] args)
{
System.Console.WriteLine("Starting Tester.");
System.Console.WriteLine("Writing Hello on wall.");
Wall wall = new Wall();
wall.writeBSTROnWall("Hello");
System.Console.WriteLine("Writing Brrrrr! on wall.");
wall.writeBSTROnWall("Brrrrr!");
System.Console.WriteLine("Reading wall:");
string wallContents = "overwrite me";
wallContents = wall.readWallBSTR();
System.Console.WriteLine("Wall says: " + wallContents);
System.Console.WriteLine("Again, Wall says: '" + wall.readWallBSTR() + "'.");
System.Console.WriteLine("\n\nDoing Bag-Ball test");
//TODO What if I create it something like: IBag bag = (IBall) Factory.BagClass(); Eberhard might have said I was supposed to be doing this sort of thing that way.
Bag bag = new Bag();
Ball ball = (Ball) bag.ProvideBall(); // TODO what if I cast it as an IBall rather than Ball
long distance_rolled;
distance_rolled = ball.roll(2);
System.Console.WriteLine("Rolling ball by 2. Accumulated distance: {0} (should say 2)", distance_rolled);
if (distance_rolled != 2) {
System.Console.WriteLine("Tester.exe: Error, distance wasn't correct. Exiting.");
Environment.Exit(-1);
}
bag.InspectBall(ball);
distance_rolled = ball.roll(9);
System.Console.WriteLine("Rolling ball by 9. Accumulated distance: {0} (should say 14)", distance_rolled);
if (distance_rolled != 14) {
System.Console.WriteLine("Tester.exe: Error, distance wasn't correct. Exiting.");
Environment.Exit(-1);
}
}
示例10: ShouldAddAnonymousObject
public void ShouldAddAnonymousObject() {
dynamic e = new Bag();
e.Foos = new { Foo1 = "Bar1", Foo2 = "Bar2" };
Assert.That(e.Foos.Foo1, Is.EqualTo("Bar1"));
Assert.That(e.Foos.Foo2, Is.EqualTo("Bar2"));
}
示例11: MainWindow
public MainWindow()
{
try
{
System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener("Debug.log"));
System.Diagnostics.Debug.AutoFlush = true;
System.Diagnostics.Debug.WriteLine(String.Format("Started at {0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Westwood\\Nox");
if (key == null)
{
MessageBox.Show("Can not find the Nox directory in the registry. You can try reinstalling Nox to fix this.", "Error");
Environment.Exit(1);
}
string installPath = (string) key.GetValue("InstallPath");
string bagPath = installPath.Substring(0, installPath.LastIndexOf("\\") + 1) + "Audio.bag";
bag = new AudioBag(bagPath);
}
catch (Exception ex)
{
MessageBox.Show("Something went very wrong. See the message in the following message box for details.", "Fatal Error");
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
throw ex;
}
//Bag bag = new VideoBag("c:\\Westwood\\Nox\\Video.bag");
//bag = new AudioBag("c:\\Westwood\\Nox\\Audio.bag");
InitializeComponent();
}
示例12: OnDoubleClick
public override void OnDoubleClick( Mobile from )
{
if (Mobiles.BaseVendor.ConsumeBackpackAndBankGold(from, m_Price))
{
Bag regBag = new Bag();
regBag.Hue = 1159;
regBag.DropItem(new Bottle(12));
regBag.DropItem(new EyesOfNewt(30));
regBag.DropItem(new BlackPearl(50));
regBag.DropItem(new Bloodmoss(50));
regBag.DropItem(new Nightshade(50));
regBag.DropItem(new Bandage(50));
regBag.DropItem(new SulfurousAsh(60));
regBag.DropItem(new Garlic(70));
regBag.DropItem(new Ginseng(70));
regBag.DropItem(new SpidersSilk(75));
regBag.DropItem(new MandrakeRoot(85));
from.Backpack.DropItem(regBag);
from.SendAsciiMessage("You've bought a bag of reagents.");
from.PlaySound(247);
}
else
from.SendAsciiMessage("You do not have enough money!");
}
示例13: Simple
public void Simple()
{
var bag = new Bag<string>
{
"aa"
};
Assert.AreEqual(bag.Count, 1);
Assert.IsTrue(bag.Contains("aa"));
Assert.AreEqual(bag["aa"], 1);
bag.Add("bb");
Assert.AreEqual(bag.Count, 2);
Assert.IsTrue(bag.Contains("bb"));
Assert.AreEqual(bag["bb"], 1);
bag.Add("aa");
Assert.AreEqual(bag.Count, 3);
Assert.IsTrue(bag.Contains("aa"));
Assert.AreEqual(bag["aa"], 2);
bag.Add("cc", 3);
Assert.AreEqual(bag.Count, 6);
Assert.IsTrue(bag.Contains("cc"));
Assert.AreEqual(bag["cc"], 3);
bag.Add("cc", 2);
Assert.AreEqual(bag.Count, 8);
Assert.IsTrue(bag.Contains("cc"));
Assert.AreEqual(bag["cc"], 5);
}
示例14: CreateAchievements
private static IEnumerable<Achievement> CreateAchievements()
{
CreateAchievementTrackerDelegate persistentKillZombieTrackerCreator = (am, ew, achievement) => new PersistentKillZombiesTracker(am, ew, achievement.Name);
PassiveSkill zombieKillReward = new PassiveSkill("Player shoots faster", passiveStats => passiveStats.FireRateMultiplier += 0.1f);
Bag<Achievement> achievements = new Bag<Achievement>();
// "important"
AchievementHelper.CreatePersistentKillingAchievements(achievements);
AchievementHelper.CreatePersistentRunningAchievements(achievements);
AchievementHelper.CreateScoreAchievements(achievements);
// "kill XXX"
AchievementHelper.CreateKillInTimeAchievements(achievements);
AchievementHelper.CreateKillRushersWhileRushingAchievements(achievements);
AchievementHelper.CreateKillWithInvulnerabilityAchievements(achievements);
AchievementHelper.CreateKillWithSingleRocketAchievments(achievements);
AchievementHelper.CreateKillGoldenGoblinsAchievements(achievements);
// "survive"
AchievementHelper.CreateSurviveWithoutKillingAchievements(achievements);
AchievementHelper.CreateSurviveWithoutMovingAchievements(achievements);
// misc
AchievementHelper.CreateLivesAtAnyPointOfGameAchievements(achievements);
AchievementHelper.CreateSpendLaserWithoutKillingAchievements(achievements);
// golden goblin
// not in atm
AchievementHelper.CreateIAPAchievements(achievements);
return achievements;
}
示例15: Associate
public void Associate(ComponentTypeFactory tf, Bag<Type> types, BitSet componentBits)
{
foreach (var t in types)
{
componentBits.Set(tf.GetIndexFor(t));
}
}