本文整理汇总了C#中System.Collections.ArrayList.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.Contains方法的具体用法?C# ArrayList.Contains怎么用?C# ArrayList.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteAssemblies
public void ExecuteAssemblies(
[UsingFactories("AssemblyNames")] string name,
[UsingFactories("AssemblyNames")] string secondName,
[UsingFactories("AssemblyNames")] string thirdName
)
{
int successCount = 0;
ArrayList names = new ArrayList();
names.Add(name);
names.Add(secondName);
names.Add(thirdName);
if (names.Contains("ChildAssembly"))
{
if (!names.Contains("SickParentAssembly"))
successCount++;
}
if (names.Contains("ParentAssembly"))
successCount++;
string[] files = new string[] { name + ".dll", secondName + ".dll", thirdName + ".dll" };
using (TestDomainDependencyGraph graph = TestDomainDependencyGraph.BuildGraph(files,null, MbUnit.Core.Filters.FixtureFilters.Any, false))
{
ReportResult result = graph.RunTests();
Assert.AreEqual(successCount, result.Counter.SuccessCount);
}
}
示例2: ExecuteAssemblies
public void ExecuteAssemblies(
[UsingFactories("AssemblyNames")] string name,
[UsingFactories("AssemblyNames")] string secondName
)
{
int successCount = 0;
ArrayList names = new ArrayList();
names.Add(Path.GetFileNameWithoutExtension(name));
names.Add(Path.GetFileNameWithoutExtension(secondName));
if (names.Contains("SickParentAssembly"))
{
if (names.Contains("ParentAssembly"))
successCount++;
}
else
{
if (names.Contains("ChildAssembly"))
successCount++;
if (names.Contains("ParentAssembly"))
successCount++;
}
string[] files = new string[] { name, secondName };
using (TestDomainDependencyGraph graph = TestDomainDependencyGraph.BuildGraph(files,null, MbUnit.Core.Filters.FixtureFilters.Any, true))
{
ReportResult result = graph.RunTests();
Assert.AreEqual(successCount, result.Counter.SuccessCount);
}
}
示例3: GetSQLServers
/// <summary>
/// Gets the array of SQL servers that are available on the LAN.
/// </summary>
/// <returns>string[] of SQL server names</returns>
public static string[] GetSQLServers()
{
string[] retval = null;
DataTable dt = null;
System.Data.Sql.SqlDataSourceEnumerator sds = System.Data.Sql.SqlDataSourceEnumerator.Instance;
dt = sds.GetDataSources();
ArrayList al = new ArrayList();
if (retval != null)
{
for (int zz = 0; zz < retval.Length; zz++)
{
if (!al.Contains(retval[zz]))
{
al.Add(retval[zz]);
}
}
}
if (dt != null)
{
foreach (DataRow row in dt.Rows)
{
string name = row["ServerName"].ToString() + (row["InstanceName"].ToString().Trim().Length != 0 ? "\\" + row["InstanceName"].ToString() : "");
if (!al.Contains(name))
{
al.Add(name);
}
}
dt.Dispose();
}
al.Sort();
return (string[])al.ToArray(typeof(string));
}
示例4: MaxSize
public void MaxSize()
{
IKernel kernel = new DefaultKernel();
kernel.AddComponent("a", typeof(PoolableComponent1));
ArrayList instances = new ArrayList();
instances.Add(kernel["a"] as PoolableComponent1);
instances.Add(kernel["a"] as PoolableComponent1);
instances.Add(kernel["a"] as PoolableComponent1);
instances.Add(kernel["a"] as PoolableComponent1);
instances.Add(kernel["a"] as PoolableComponent1);
PoolableComponent1 other1 = kernel["a"] as PoolableComponent1;
Assert.IsNotNull(other1);
Assert.IsTrue(!instances.Contains(other1));
foreach(object inst in instances)
{
kernel.ReleaseComponent(inst);
}
kernel.ReleaseComponent(other1);
PoolableComponent1 other2 = kernel["a"] as PoolableComponent1;
Assert.IsNotNull(other2);
Assert.IsTrue(other1 != other2);
Assert.IsTrue(instances.Contains(other2));
kernel.ReleaseComponent(other2);
}
示例5: ProduceAddEx
public ArrayList ProduceAddEx(int volume, int maxFactor, double fillInBlankPercentage)
{
string operation = "+";
if (fillInBlankPercentage > 1)
fillInBlankPercentage = 1;
else if (fillInBlankPercentage < 0)
fillInBlankPercentage = 0;
int blankVolume = (int)(volume * fillInBlankPercentage);
int nonBlankVolume = volume - blankVolume;
ArrayList exList = new ArrayList();
if (maxFactor < 1)
{
return exList;
}
// 如果难度超过20就不出现因子0、1这种简单题目了
int minFactor = (maxFactor > 20 ? 2 : 0);
// 减少重复题目,如果发现重复则再试一次
// 另外如果难度太低可能会导致无法保证不重复的情况下出够题目同时也考虑效率问题,只重试10次
int repeatedTimes = 0;
Random random = new Random();
for (int i = 0; i < nonBlankVolume; )
{
int factor1 = random.Next(minFactor, maxFactor - minFactor);
int factor2 = random.Next(minFactor, Math.Max(minFactor + 1, maxFactor - factor1));
string equation = factor1 + operation + factor2 + "=";
if (repeatedTimes > 10 || !exList.Contains(equation))
{
exList.Add(equation);
repeatedTimes = 0;
i++;
}
else
{
repeatedTimes++;
}
}
for (int i = 0; i < blankVolume; )
{
int factor1 = random.Next(minFactor, maxFactor - minFactor);
int factor2 = random.Next(minFactor, Math.Max(minFactor + 1, maxFactor - factor1));
string equation;
if (random.Next() % 2 == 0)
equation = factor1 + operation + "( )" + "=" + (factor1 + factor2);
else
equation = "( )" + operation + factor2 + "=" + (factor1 + factor2);
if (repeatedTimes > 10 || !exList.Contains(equation))
{
exList.Add(equation);
repeatedTimes = 0;
i++;
}
else
{
repeatedTimes++;
}
}
return exList;
}
示例6: GetWhisperKeywords
public static string[] GetWhisperKeywords()
{
ArrayList keywords = new ArrayList();
String whisperKeyword = null;
foreach (DataRow row in DB.ActionTable.Rows)
{
if (row[DB.COL_QUESTPARTACTION_P] is string && ((string)row[DB.COL_QUESTPARTACTION_P]).Contains("["))
{
MatchCollection matches = Regex.Matches((string)row[DB.COL_QUESTPARTACTION_P], "\\[([^\\]])*\\]", RegexOptions.Compiled);
foreach (Match match in matches)
{
whisperKeyword = match.Value.Trim(WHISPER_TRIMS);
if (!keywords.Contains(whisperKeyword))
keywords.Add(whisperKeyword);
}
}
if (row[DB.COL_QUESTPARTACTION_Q] is string && ((string)row[DB.COL_QUESTPARTACTION_Q]).Contains("["))
{
MatchCollection matches = Regex.Matches((string)row[DB.COL_QUESTPARTACTION_Q], "\\[([^\\]])*\\]", RegexOptions.Compiled);
foreach (Match match in matches)
{
whisperKeyword = match.Value.Trim(WHISPER_TRIMS);
if (!keywords.Contains(whisperKeyword))
keywords.Add(whisperKeyword);
}
}
}
return (string[])keywords.ToArray(typeof(string));
}
示例7: OnActionExecuted
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
var todoBD = db.TODOes.ToList().Where(m=>m.done_date == null).OrderBy(m=> m.project_name).OrderBy(m=> m.add_date);
ArrayList lista_projektow = new ArrayList();
Hashtable lista_todo_do_zrobienia = new Hashtable();
if (todoBD != null)
{
foreach (TODO todo in todoBD)
{
if (!lista_projektow.Contains(todo.project_name))
lista_projektow.Add(todo.project_name);
}
foreach (string nazwa_projektu in lista_projektow)
{
ArrayList lista_zadan_do_wykonania = new ArrayList();
foreach (TODO todo in todoBD)
{
if (todo.project_name == nazwa_projektu)
lista_zadan_do_wykonania.Add(todo);
}
lista_todo_do_zrobienia.Add(nazwa_projektu, lista_zadan_do_wykonania);
}
}
todoBD = db.TODOes.ToList().Where(m => m.done_date != null).OrderBy(m => m.project_name).OrderByDescending(m => m.done_date);
Hashtable lista_todo_zrobione = new Hashtable();
if (todoBD != null)
{
lista_projektow.Clear();
foreach (TODO todo in todoBD)
{
if (!lista_projektow.Contains(todo.project_name))
lista_projektow.Add(todo.project_name);
}
foreach (string nazwa_projektu in lista_projektow)
{
ArrayList lista_zadan_wykonanych = new ArrayList();
foreach (TODO todo in todoBD)
{
if (todo.project_name == nazwa_projektu)
lista_zadan_wykonanych.Add(todo);
}
lista_todo_zrobione.Add(nazwa_projektu, lista_zadan_wykonanych);
}
}
ViewData.Add("lista_todo_do_zrobienia", lista_todo_do_zrobienia);
ViewData.Add("lista_todo_zrobione", lista_todo_zrobione);
}
示例8: HasMultipleCategories
public void HasMultipleCategories()
{
XmlNodeList categories = resultDoc.SelectNodes("//test-case[@name=\"NUnit.Tests.Assemblies.MockTestFixture.MockTest3\"]/categories/category");
Assert.IsNotNull(categories);
Assert.AreEqual(2, categories.Count);
ArrayList names = new ArrayList();
names.Add( categories[0].Attributes["name"].Value );
names.Add( categories [1].Attributes["name"].Value);
Assert.IsTrue( names.Contains( "AnotherCategory" ), "AnotherCategory" );
Assert.IsTrue( names.Contains( "MockCategory" ), "MockCategory" );
}
示例9: EventSink_PlayerDeath
public static void EventSink_PlayerDeath( PlayerDeathEventArgs e )
{
Mobile m = e.Mobile;
ArrayList killers = new ArrayList();
ArrayList toGive = new ArrayList();
foreach ( AggressorInfo ai in m.Aggressors )
{
//bounty system edit
// orig if ( ai.Attacker.Player && ai.CanReportMurder && !ai.Reported )
if ( ai.Attacker.Player && ai.CanReportMurder && !ai.Reported &&
!BountyBoard.Attackable( ai.Attacker, e.Mobile ) ) // end bounty system edit
{
killers.Add( ai.Attacker );
ai.Reported = true;
}
if ( ai.Attacker.Player && (DateTime.Now - ai.LastCombatTime) < TimeSpan.FromSeconds( 30.0 ) && !toGive.Contains( ai.Attacker ) )
toGive.Add( ai.Attacker );
}
foreach ( AggressorInfo ai in m.Aggressed )
{
if ( ai.Defender.Player && (DateTime.Now - ai.LastCombatTime) < TimeSpan.FromSeconds( 30.0 ) && !toGive.Contains( ai.Defender ) )
toGive.Add( ai.Defender );
}
foreach ( Mobile g in toGive )
{
int n = Notoriety.Compute( g, m );
int theirKarma = m.Karma, ourKarma = g.Karma;
bool innocent = ( n == Notoriety.Innocent );
bool criminal = ( n == Notoriety.Criminal || n == Notoriety.Murderer );
int fameAward = m.Fame / 200;
int karmaAward = 0;
if ( innocent )
karmaAward = ( ourKarma > -2500 ? -850 : -110 - (m.Karma / 100) );
else if ( criminal )
karmaAward = 50;
Titles.AwardFame( g, fameAward, false );
Titles.AwardKarma( g, karmaAward, true );
}
if ( m is PlayerMobile && ((PlayerMobile)m).NpcGuild == NpcGuild.ThievesGuild )
return;
if ( killers.Count > 0 )
new GumpTimer( m, killers ).Start();
}
示例10: WriteLog
/// <summary>
/// Writes the log.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="stream">The stream.</param>
/// <param name="callback">The callback for UI updates.</param>
public void WriteLog(IExecutionContext context, Stream stream, ProgressCallback callback)
{
TimeSpan baseTime = new TimeSpan(0);
ArrayList oids = new ArrayList();
Hashtable bitsByOid = new Hashtable();
using (StreamWriter s = new StreamWriter(stream))
{
foreach (PacketLog log in context.LogManager.Logs)
{
for (int i = 0; i < log.Count; i++)
{
if (callback != null && (i & 0xFFF) == 0) // update progress every 4096th packet
callback(i, log.Count - 1);
StoC_0xA1_NpcUpdate npcUpdate = log[i] as StoC_0xA1_NpcUpdate;
if (npcUpdate == null) continue;
if ((npcUpdate.Temp & 0xF000) == 0) continue;
if ((npcUpdate.Temp & 0x0FFF) != 0) continue;
s.WriteLine(npcUpdate.ToHumanReadableString(baseTime, true));
if (!oids.Contains(npcUpdate.NpcOid))
oids.Add(npcUpdate.NpcOid);
ArrayList bitsList = (ArrayList) bitsByOid[npcUpdate.NpcOid];
if (bitsList == null)
{
bitsList = new ArrayList();
bitsByOid[npcUpdate.NpcOid] = bitsList;
}
int bits = npcUpdate.Temp >> 12;
if (!bitsList.Contains(bits))
bitsList.Add(bits);
}
int regionId;
int zoneId;
SortedList oidInfo = ShowKnownOidAction.MakeOidList(log.Count - 1, log, out regionId, out zoneId);
s.WriteLine("\n\noids for region {0}, zone {1}\n", regionId, zoneId);
foreach (DictionaryEntry entry in oidInfo)
{
ushort oid = (ushort) entry.Key;
if (!oids.Contains(oid)) continue;
ShowKnownOidAction.ObjectInfo objectInfo = (ShowKnownOidAction.ObjectInfo) entry.Value;
s.Write("0x{0:X4}: ", oid);
s.Write(objectInfo.ToString());
foreach (int bits in (ArrayList) bitsByOid[oid])
{
s.Write("\t0b{0}", Convert.ToString(bits, 2));
}
s.WriteLine();
}
}
}
}
示例11: GetPropertiesTest
public void GetPropertiesTest()
{
Collection<PropertyInfo> properties = _objectUtility.GetProperties(typeof(DummyObject));
ArrayList propertyNames = new ArrayList();
foreach (PropertyInfo property in properties)
propertyNames.Add(property.Name);
Assert.That(propertyNames.Contains("StringProperty"));
Assert.That(propertyNames.Contains("IntProperty"));
Assert.That(propertyNames.Contains("DecimalProperty"));
Assert.That(propertyNames.Contains("ObjectProperty"));
}
示例12: GetSubstitutionsImplicitly
public void GetSubstitutionsImplicitly()
{
XmlNode node = _document.DocumentElement.FirstChild;
var templater = new XmlTemplater(node);
string[] substitutions = templater.Substitutions;
Assert.AreEqual(4, substitutions.Length);
var list = new ArrayList(substitutions);
Assert.IsTrue(list.Contains("color"));
Assert.IsTrue(list.Contains("name"));
Assert.IsTrue(list.Contains("state"));
Assert.IsTrue(list.Contains("direction"));
}
示例13: OnResponse
public override void OnResponse(NetState sender, RelayInfo info)
{
Mobile from = sender.Mobile;
this.caller = sender.Mobile;
switch (info.ButtonID)
{
case 1:
{
TextRelay entrySphereAcc = info.GetTextEntry(10);
this.textSphereAcc = (entrySphereAcc == null ? "" : entrySphereAcc.Text.Trim());
TextRelay entrySphereChar = info.GetTextEntry(11);
this.textSphereChar = (entrySphereChar == null ? "" : entrySphereChar.Text.Trim());
TextRelay entryRunUOAcc = info.GetTextEntry(12);
this.textRunUOAcc = (entryRunUOAcc == null ? "" : entryRunUOAcc.Text.Trim());
TextRelay entryRunUOChar = info.GetTextEntry(13);
this.textRunUOChar = (entryRunUOChar == null ? "" : entryRunUOChar.Text.Trim());
ArrayList Selections = new ArrayList(info.Switches);
if (Selections.Contains(20))
this.importSkills = true;
else
this.importSkills = false;
if (Selections.Contains(21))
this.importItensToPlayer = true;
else
this.importItensToPlayer = false;
if (Selections.Contains(22))
this.importItensToStaff = true;
else
this.importItensToStaff = false;
StartImport();
break;
}
case 0:
default:
caller.SendMessage("Importacao CANCELADA.");
break;
}
}
示例14: CanCreateFrom
/// <summary>
/// Does the passed data object have this format?
/// </summary>
/// <param name="dataObject">data object</param>
/// <returns>true if the data object has the format, otherwise false</returns>
public bool CanCreateFrom(IDataObject dataObject)
{
// GetDataPresent is not always a reliable indicator of what data is
// actually available. For Outlook Express, if you call GetDataPresent on
// FileGroupDescriptor it returns false however if you actually call GetData
// you will get the FileGroupDescriptor! Therefore, we are going to
// enumerate the available formats and check that list rather than
// checking GetDataPresent
ArrayList formats = new ArrayList(dataObject.GetFormats());
// check for FileContents
return (formats.Contains(DataFormatsEx.FileGroupDescriptorFormat) ||
formats.Contains(DataFormatsEx.FileGroupDescriptorWFormat))
&& formats.Contains(DataFormatsEx.FileContentsFormat);
}
示例15: GetSubstititionsExplicitly
public void GetSubstititionsExplicitly()
{
XmlNode node = _document.DocumentElement.FirstChild;
var element = (XmlElement) node;
element.SetAttribute(InstanceMemento.SUBSTITUTIONS_ATTRIBUTE, "direction,color");
var templater = new XmlTemplater(node);
string[] substitutions = templater.Substitutions;
Assert.AreEqual(2, substitutions.Length);
var list = new ArrayList(substitutions);
Assert.IsTrue(list.Contains("color"));
Assert.IsTrue(list.Contains("direction"));
}