本文整理汇总了C#中System.Collections.ArrayList.InsertRange方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.InsertRange方法的具体用法?C# ArrayList.InsertRange怎么用?C# ArrayList.InsertRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.InsertRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatContentLocation
public static string FormatContentLocation(string contentLocation, string queryString)
{
var token = new char[] { '/' };
var locationArray = contentLocation.Split(token);
var locationArrayList = new ArrayList(locationArray);
// Create CDN Address as array so we can insert it into url array at appropriate point
var cdnAddressArray = new List<string> { CdnEndpoint };
// Replace root element with http address for CDN
if (CdnEndpoint.StartsWith("http") && ((locationArrayList[0].ToString() == "~") || (locationArrayList[0].ToString() == ".")))
{
locationArrayList[0] = CdnEndpoint;
}
else if (locationArrayList[0].ToString() == "~" || locationArrayList[0].ToString() == ".")
{
locationArrayList.InsertRange(1, cdnAddressArray);
}
else
{
locationArrayList.InsertRange(0, cdnAddressArray);
}
var newUrl = String.Join("/", locationArrayList.ToArray());
newUrl = newUrl + queryString;
return newUrl;
}
示例2: Recombine
public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
{
double maleConstraint = random.NextDouble();
int maleCount = (int)Math.Ceiling(maleGenes.Count * maleConstraint);
int femaleCount = (int)Math.Floor(femaleGenes.Count * (1-maleConstraint));
ArrayList child = new ArrayList(maleCount + femaleCount);
child.InsertRange(0, maleGenes.GetRange(0, maleCount));
child.InsertRange(maleCount, femaleGenes.GetRange(femaleGenes.Count - femaleCount, femaleCount));
for (int i = 0; i < child.Count; i++)
child[i] = (child[i] as IGene).Clone();
return child;
}
示例3: Recombine
public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
{
if (maleGenes.Count != femaleGenes.Count)
throw new GenesIncompatibleException();
ArrayList child = new ArrayList(maleGenes.Count);
int middle = maleGenes.Count / 2;
child.InsertRange(0, maleGenes.GetRange(0, middle).Clone() as ArrayList);
child.InsertRange(middle, femaleGenes.GetRange(middle, femaleGenes.Count - middle).Clone() as ArrayList);
// Create Deep Copy
for (int i = 0; i < child.Count; i++)
child[i] = (child[i] as IGene).Clone();
return child;
}
示例4: fun1
public void fun1()
{
ArrayList a1 = new ArrayList();
a1.Add(1);
a1.Add('c');
a1.Add("string1");
ArrayList al2 = new ArrayList();
al2.Add('a');
al2.Add(5);
int n = (int)a1[0];
Console.WriteLine(n);
a1[0] = 20;
Console.WriteLine(a1.Count);
Console.WriteLine(a1.Contains(55));
Console.WriteLine(a1.IndexOf(55));
//int[] num = (int[])a1.ToArray();
a1.Add(45);
a1.Add(12);
a1.Add(67);
a1.Insert(1, "new value");
//a1.AddRange(al2);
a1.InsertRange(1, al2);
a1.Remove("string1");
a1.RemoveAt(2);
a1.RemoveRange(0, 2);
foreach (object o in a1)
{
Console.WriteLine(o.ToString());
}
}
示例5: Test
public void Test(int arg)
{
ArrayList items = new ArrayList();
items.Add(1);
items.AddRange(1, 2, 3);
items.Clear();
bool b1 = items.Contains(2);
items.Insert(0, 1);
items.InsertRange(1, 0, 5);
items.RemoveAt(4);
items.RemoveRange(4, 3);
items.Remove(1);
object[] newItems = items.GetRange(5, 2);
object[] newItems2 = items.GetRange(5, arg);
List<int> numbers = new List<int>();
numbers.Add(1);
numbers.AddRange(1, 2, 3);
numbers.Clear();
bool b2 = numbers.Contains(4);
numbers.Insert(1, 10);
numbers.InsertRange(2, 10, 3);
numbers.RemoveAt(4);
numbers.RemoveRange(4, 2);
int[] newNumbers = items.GetRange(5, 2);
int[] newNumbers2 = items.GetRange(5, arg);
string[] words = new string[5];
words[0] = "hello";
words[1] = "world";
bool b3 = words.Contains("hi");
string[] newWords = words.GetRange(5, 2);
string[] newWords2 = words.GetRange(5, arg);
}
示例6: TestInsert
public void TestInsert()
{
ArrayList anArrayList = new ArrayList();
anArrayList.Insert( anArrayList.Count, "Moo!" );
Assert.AreEqual (1, anArrayList.Count);
Assert.AreSame ("Moo!", anArrayList[0]);
anArrayList.InsertRange( 1, new ArrayList(){1,2,3,4,5,6,7,8,9} );
Assert.AreEqual (10, anArrayList.Count);
}
示例7: OnAuthenticate
void OnAuthenticate(object sender, EventArgs e)
{
app = (HttpApplication)sender;
HttpRequest req = app.Request;
HttpResponse res = app.Response;
string loginUrl = ConfigurationSettings.AppSettings[LOGINURL_KEY];
if(loginUrl == null || loginUrl.Trim() == String.Empty)
{
throw new Exception(" CustomAuthentication.LoginUrl entry not found in appSettings section of Web.config");
}
string cookieName = ConfigurationSettings.AppSettings[AUTHENTICATION_COOKIE_KEY];
if(cookieName == null || cookieName.Trim() == String.Empty)
{
throw new Exception(" CustomAuthentication.Cookie.Name entry not found in appSettings section section of Web.config");
}
int i = req.Path.LastIndexOf("/");
string page = req.Path.Substring(i+1, (req.Path.Length - (i + 1)));
int j = loginUrl.LastIndexOf("/");
string loginPage = loginUrl.Substring(j+1, (loginUrl.Length - (j + 1)));
if(page != null && !(page.Trim().ToUpper().Equals(loginPage.ToUpper())))
{
if(req.Cookies.Count > 0 && req.Cookies[cookieName.ToUpper()] != null)
{
HttpCookie cookie = req.Cookies[cookieName.ToUpper()];
if(cookie != null)
{
string str = cookie.Value;
CustomIdentity userIdentity = CustomAuthentication.Decrypt(str);
string[] roles = userIdentity.UserRoles.Split(new char[]{'|'});
ArrayList arrRoles = new ArrayList();
arrRoles.InsertRange(0, roles);
CustomPrincipal principal = new CustomPrincipal(userIdentity, arrRoles);
app.Context.User = principal;
Thread.CurrentPrincipal = principal;
}
}
else
{
res.Redirect(req.ApplicationPath + loginUrl + "?ReturnUrl=" + req.Path, true);
}
}
}
示例8: DrawPath
//Code to draw path for the line
public override void DrawPath()
{
if (Container == null) return;
if (ControlPoints == null) return;
//Get the start and end location depending on start shapes etc
PointF startLocation = GetOriginLocation(Start,End);
PointF endLocation = GetOriginLocation(End,Start);
//Add the points to the solution
ArrayList points = new ArrayList();
points.Add(startLocation);
//Add the control points
//If bezier must be 2,5,8 control points etc
PointF[] controlPoints;
//Set up control points
if (CurveType == CurveType.Bezier)
{
//Must be 2, 5, 8 etc
if (mControlPoints.GetUpperBound(0) < 1) throw new CurveException("Bezier must contain at least 2 control points.");
int intMax = (((int) (mControlPoints.GetUpperBound(0) - 1) / 3) * 3) + 2;
controlPoints = new PointF[intMax];
for (int i = 0; i < intMax; i++ )
{
controlPoints[i] = mControlPoints[i];
}
}
else
{
controlPoints = mControlPoints;
}
points.InsertRange(1,controlPoints);
//Add the end points
points.Add(endLocation);
//Draw the path
GraphicsPath path = new GraphicsPath();
if (CurveType == CurveType.Bezier)
{
path.AddBeziers((PointF[]) points.ToArray(typeof(PointF)));
}
else
{
path.AddCurve((PointF[]) points.ToArray(typeof(PointF)),Tension);
}
SetPoints(points);
//Calculate path rectangle
RectangleF rect = path.GetBounds();
SetRectangle(rect); //Sets the bounding rectangle
SetPath(path); //setpath moves the line to 0,0
}
示例9: DeserializeItem
public static OpmlItem[] DeserializeItem(XPathNavigator nav)
{
ArrayList items = new ArrayList();
if (nav.HasAttributes)
{
string title = nav.GetAttribute("title", "");
if (String.IsNullOrEmpty(title))
title = nav.GetAttribute("text", "");
string htmlUrl = nav.GetAttribute("htmlurl", "");
if (String.IsNullOrEmpty(htmlUrl))
htmlUrl = nav.GetAttribute("htmlUrl", "");
string xmlUrl = nav.GetAttribute("xmlurl", "");
if (String.IsNullOrEmpty(xmlUrl))
xmlUrl = nav.GetAttribute("xmlUrl", "");
OpmlItem currentItem = null;
string description = nav.GetAttribute("description", "");
if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(htmlUrl))
currentItem = new OpmlItem(title, description, xmlUrl, htmlUrl);
if (null != currentItem)
items.Add(currentItem);
}
if (nav.HasChildren)
{
XPathNodeIterator childItems = nav.SelectChildren("outline", "");
while (childItems.MoveNext())
{
OpmlItem[] children = DeserializeItem(childItems.Current);
if (null != children)
items.InsertRange(items.Count, children);
}
}
OpmlItem[] result = new OpmlItem[items.Count];
items.CopyTo(result);
return result;
}
示例10: AddNewRecords
protected virtual void AddNewRecords()
{
ArrayList newRecordList = new ArrayList();
System.Collections.Generic.List<Hashtable> newUIDataList = new System.Collections.Generic.List<Hashtable>();
// Loop though all the record controls and if the record control
// does not have a unique record id set, then create a record
// and add to the list.
if (!this.ResetData)
{
System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "UOMTableControlRepeater"));
if (rep == null){return;}
foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
{
// Loop through all rows in the table, set its DataSource and call DataBind().
UOMTableControlRow recControl = (UOMTableControlRow)(repItem.FindControl("UOMTableControlRow"));
if (recControl.Visible && recControl.IsNewRecord) {
UOMRecord rec = new UOMRecord();
if (recControl.Status.Text != "") {
rec.Parse(recControl.Status.Text, UOMTable.Status);
}
if (recControl.UOMDescription.Text != "") {
rec.Parse(recControl.UOMDescription.Text, UOMTable.UOMDescription);
}
if (recControl.UOMName.Text != "") {
rec.Parse(recControl.UOMName.Text, UOMTable.UOMName);
}
newUIDataList.Add(recControl.PreservedUIData());
newRecordList.Add(rec);
}
}
}
// Add any new record to the list.
for (int count = 1; count <= this.AddNewRecord; count++) {
newRecordList.Insert(0, new UOMRecord());
newUIDataList.Insert(0, new Hashtable());
}
this.AddNewRecord = 0;
// Finally, add any new records to the DataSource.
if (newRecordList.Count > 0) {
ArrayList finalList = new ArrayList(this.DataSource);
finalList.InsertRange(0, newRecordList);
Type myrec = typeof(FPCEstimate.Business.UOMRecord);
this.DataSource = (UOMRecord[])(finalList.ToArray(myrec));
}
// Add the existing UI data to this hash table
if (newUIDataList.Count > 0)
this.UIData.InsertRange(0, newUIDataList);
}
示例11: TestEnumerator
public void TestEnumerator ()
{
String [] s1 = { "this", "is", "a", "test" };
ArrayList al1 = new ArrayList (s1);
IEnumerator en = al1.GetEnumerator ();
en.MoveNext ();
al1.Add ("something");
try {
en.MoveNext ();
Assert.Fail ("Add() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.AddRange (al1);
try {
en.MoveNext ();
Assert.Fail ("AddRange() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.Clear ();
try {
en.MoveNext ();
Assert.Fail ("Clear() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
al1 = new ArrayList (s1);
en = al1.GetEnumerator ();
en.MoveNext ();
al1.Insert (0, "new first");
try {
en.MoveNext ();
Assert.Fail ("Insert() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.InsertRange (0, al1);
try {
en.MoveNext ();
Assert.Fail ("InsertRange() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.Remove ("this");
try {
en.MoveNext ();
Assert.Fail ("Remove() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.RemoveAt (2);
try {
en.MoveNext ();
Assert.Fail ("RemoveAt() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.RemoveRange (1, 1);
try {
en.MoveNext ();
Assert.Fail ("RemoveRange() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.Reverse ();
try {
en.MoveNext ();
Assert.Fail ("Reverse() didn't invalidate the enumerator");
} catch (InvalidOperationException) {
// do nothing...this is what we expect
}
en = al1.GetEnumerator ();
en.MoveNext ();
al1.Sort ();
try {
en.MoveNext ();
//.........这里部分代码省略.........
示例12: TestInsertRange
public void TestInsertRange ()
{
{
bool errorThrown = false;
try {
ArrayList al1 =
ArrayList.FixedSize (new ArrayList ());
string [] s = { "Hi!" };
al1.InsertRange (0, s);
} catch (NotSupportedException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "insert to fixed size error not thrown");
}
{
bool errorThrown = false;
try {
ArrayList al1 =
ArrayList.ReadOnly (new ArrayList ());
string [] s = { "Hi!" };
al1.InsertRange (0, s);
} catch (NotSupportedException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "insert to read only error not thrown");
}
{
bool errorThrown = false;
try {
ArrayList al1 = new ArrayList (3);
string [] s = { "Hi!" };
al1.InsertRange (-1, s);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "negative index insert error not thrown");
}
{
bool errorThrown = false;
try {
ArrayList al1 = new ArrayList (3);
string [] s = { "Hi!" };
al1.InsertRange (4, s);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "out-of-range insert error not thrown");
}
{
bool errorThrown = false;
try {
ArrayList al1 = new ArrayList (3);
al1.InsertRange (0, null);
} catch (ArgumentNullException) {
errorThrown = true;
}
Assert.IsTrue (errorThrown, "null insert error not thrown");
}
{
char [] c = { 'a', 'b', 'c' };
ArrayList a = new ArrayList (c);
a.InsertRange (1, c);
Assert.AreEqual ('a', a [0], "bad insert 1");
Assert.AreEqual ('a', a [1], "bad insert 2");
Assert.AreEqual ('b', a [2], "bad insert 3");
Assert.AreEqual ('c', a [3], "bad insert 4");
Assert.AreEqual ('b', a [4], "bad insert 5");
Assert.AreEqual ('c', a [5], "bad insert 6");
}
}
示例13: RemoveNodeAndPromoteChildren
RemoveNodeAndPromoteChildren(ArrayList nodes, int indexToRemove)
{
ProgressNode nodeToRemove = (ProgressNode)nodes[indexToRemove];
Dbg.Assert(nodes != null, "can't remove nodes from a null list");
Dbg.Assert(indexToRemove < nodes.Count, "index is not in list");
Dbg.Assert(nodeToRemove != null, "no node at specified index");
if (nodeToRemove == null)
{
return;
}
if (nodeToRemove.Children != null)
{
// promote the children.
for (int i = 0; i < nodeToRemove.Children.Count; ++i)
{
// unparent the children. If the children are ever updated again, they will be reparented.
((ProgressNode)nodeToRemove.Children[i]).ParentActivityId = -1;
}
// add the children as siblings
nodes.RemoveAt(indexToRemove);
--_nodeCount;
nodes.InsertRange(indexToRemove, nodeToRemove.Children);
#if DEBUG || ASSERTIONS_TRACE
Dbg.Assert(_nodeCount == this.CountNodes(), "We've lost track of the number of nodes in the tree");
#endif
}
else
{
// nothing to promote
RemoveNode(nodes, indexToRemove);
return;
}
}
示例14: InsertRange
} // 1.0.012
#endregion
#region Private Methods
// private void InsertRange(bool replace, int index, params System.Windows.Forms.TabPage[] theTabPages)
//
private void InsertRange(bool replace, int index, params System.Windows.Forms.TabPage[] theTabPages)// 1.0.010
{ // 1.0.004
#region Put existing [base.TabPages] into an ArrayList sequenced in the present order
System.Collections.ArrayList alTabPages = new System.Collections.ArrayList(this.Count); // 1.0.003
for (int idx = 0; idx < this.Count; idx++) // 1.0.003
{ // 1.0.003
alTabPages.Add(base[idx]); // 1.0.010
} // 1.0.003
#endregion
#region Add/Insert [theTabPages] at appropriate location in the ArrayList
if (replace // Replace TabPage at [index] with [theTabPages]? // 1.0.004
&& ((index >= 0) && (index < alTabPages.Count)) ) // 1.0.004
{ // 1.0.004
alTabPages.RemoveAt(index); // 1.0.004
} // 1.0.004
if ((index >= 0) && (index < alTabPages.Count)) // 1.0.004
{ // 1.0.004
alTabPages.InsertRange(index, theTabPages); // 1.0.004
} // 1.0.004
else // 1.0.004
{ // 1.0.004
alTabPages.AddRange(theTabPages); // 1.0.004
} // 1.0.004
#endregion
#region Rebuild the [base.TabPages] Collection
_owner.SuspendLayout(); // 1.0.003
base.Clear(); // 1.0.003
for (int idxNew = 0; idxNew < alTabPages.Count; idxNew++) // 1.0.003
{ // 1.0.003
System.Windows.Forms.TabPage aTabPage = (System.Windows.Forms.TabPage)alTabPages[idxNew]; // 1.0.010
aTabPage.TabIndex = idxNew; // 1.0.003
base.Add(aTabPage); // 1.0.003
} // 1.0.003
alTabPages.Clear(); // 1.0.003
_owner.ResumeLayout(false); // 1.0.003
_owner.Invalidate(); // 1.0.003
#endregion
} // 1.0.004
示例15: CreateLimitedViewOfDataSet
private void CreateLimitedViewOfDataSet(out EMDataSet dataSet, out string friendlyConstraints)
{
dataSet = null;
friendlyConstraints = null;
ReportDialog dlg = new ReportDialog();
if (dlg.ShowDialog() != DialogResult.OK)
return;
ArrayList constraints = dlg.GetPOHeaderConstraints();
friendlyConstraints = dlg.GetFriendlyConstraints();
ArrayList maybeConstraints = dlg.GetMaybePOHeaderConstraints(); // sometimes applies per item
//, sometimes for entire PO.
string constraintsAsStr = DataInterface.TranslateToConstraint(constraints);
string maybeConstraintsAsStr = DataInterface.TranslateToConstraint(maybeConstraints);
constraintsAsStr = AddMaybeConstraints(constraintsAsStr, maybeConstraintsAsStr);
dataSet = new EMDataSet();
using (new OpenConnection(EM.IsWrite.No, AdapterHelper.Connection))
using (new TurnOffConstraints(dataSet))
{
AdapterHelper.FillCurrency(dataSet);
AdapterHelper.FillAllPOHeaders(dataSet, constraintsAsStr);
foreach (EMDataSet.POHeaderTblRow poRow in dataSet.POHeaderTbl)
{
ArrayList poItemconstraints = new ArrayList();
string constraint = "POID = " + poRow.POID.ToString();
poItemconstraints.Add(constraint);
constraint = "CancelDate IS NULL";
poItemconstraints.Add(constraint);
ArrayList orConstraints;
ArrayList constraints2 = dlg.GetPOItemConstraints(out orConstraints);
poItemconstraints.InsertRange(0, constraints2);
if (poRow.MillConfirmationAppliesToEntirePO == 0)
{
poItemconstraints.InsertRange(0, maybeConstraints);
}
constraint = DataInterface.TranslateToConstraint(poItemconstraints, orConstraints);
AdapterHelper.FillPOItemsWithConstraints(dataSet, constraint);
}
AdapterHelper.FillOutConstraints(dataSet);
}
AddAuxiliaryFieldInfo(dataSet);
}