本文整理汇总了C#中System.Collections.ArrayList.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.Insert方法的具体用法?C# ArrayList.Insert怎么用?C# ArrayList.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwapPosition
public static void SwapPosition(ArrayList lista, Object node1, Object node2)
{
int exp1idx = lista.IndexOf(node1);
int exp2idx = lista.IndexOf(node2);
lista.RemoveAt(exp1idx);
lista.Insert(exp1idx, node2);
lista.RemoveAt(exp2idx);
lista.Insert(exp2idx, node1);
}
示例2: Delete
/// <summary>
/// Deletes a List of Strings from the CSV File
/// </summary>
/// <param name="DeleteItems"></param>
public void Delete(List<string> DeleteItems)
{
//SaveToFile
try
{
ArrayList temp = new ArrayList();
///reads the file
///adds it to the array
StreamReader inputStream = File.OpenText(oldLocal);
string line;
line = inputStream.ReadLine();
for (int i = 0; line != null; i++)
{
bool ignore = false;
foreach (string deleteItem in DeleteItems)
{
string[] breakUp = line.Split(',');
string itemName = breakUp[0] + "/" + breakUp[3];
if (itemName.CompareTo(deleteItem) == 0)
{
try
{
File.Delete(breakUp[4]);
temp.Insert(i, "");
ignore = true;
break;
}
catch
{
MessageBox.Show("File :" + breakUp[0] + " " + breakUp[3] + " is in use. Close file before deleting");
}
}
}
if (!ignore)
{
temp.Insert(i, line);
}
line = inputStream.ReadLine();
}
inputStream.Close();
StreamWriter outputStream = File.CreateText(oldLocal);
for (int g = 0; g < temp.Count; g++)
{
if (temp[g] != null && temp[g] != "")
{
outputStream.WriteLine(temp[g]);
}
}
outputStream.Close();
}
catch (Exception e)
{
MessageBox.Show("CSV ERROR: " + e);
}
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//1. create empty ArrayList
ArrayList al = new ArrayList();
//2. add element into array list
al.Add("Dog");
al.Add("Cat");
al.Add("Elephant");
al.Add("Lion");
al.Add("Cat");
al.Add("Platypus");
//3. bind above arrayList to first list box
lbOriginal.DataSource = al;
lbOriginal.DataBind();
//4. change (insert -> remove ->remove)
al.Insert(1, "Chicken~~~");
al.Remove("Cat");
al.RemoveAt(0);
//5. bind the result into second list box
lbChanged.DataSource = al;
lbChanged.DataBind();
}
示例4: TinhBieuThuc
public TinhBieuThuc(string input)
{
PhepTinh = new PhepTinh();
BieuThuc = new ArrayList();
input = input.Replace(" ", "") + ")";
string temp = "";
int tag = 0;
while (input != "") {
bool isDigit = isNumber(input[0])
||
(tag == 0 && input[0] == '-' && char.IsDigit(input[1]));
if (isDigit) {
tag = 1;
do {
temp += input[0].ToString();
input = input.Substring(1);
} while (isNumber(input[0]) && input[0] != '-');
BieuThuc.Add(double.Parse(temp));
temp = "";
}
else {
tag = 0;
BieuThuc.Add(input[0].ToString());
input = input.Substring(1);
}
}
for (int i = 0; i < BieuThuc.Count - 1; i++) {
if (isDouble(BieuThuc[i]) && isDouble(BieuThuc[i + 1])) {
BieuThuc.Insert(i + 1, "+");
}
}
}
示例5: InsertUpdateEvent
public void InsertUpdateEvent(ArrayList Event)
{
CRM.DataAccess.AdministratorEntity.EventStoredProcedure objinsertevent = new CRM.DataAccess.AdministratorEntity.EventStoredProcedure();
Event.Insert(3, Session["usersid"].ToString());
objinsertevent.InsertUpdateEventMaster(Event);
}
示例6: InsertUpdateAgentName
public void InsertUpdateAgentName(ArrayList Agent)
{
AgentMasterStoredProcedure objagent = new AgentMasterStoredProcedure();
Agent.Insert(13, Session["usersid"].ToString());
objagent.InsertUpdateAgentName(Agent);
}
示例7: 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);
}
示例8: InsertUpdateProfileInfo
public void InsertUpdateProfileInfo(ArrayList Profile)
{
UserProfileStoredProcedure objeditprofile = new UserProfileStoredProcedure();
Profile.Insert(14, Session["usersid"].ToString());
objeditprofile.InsertUpdateProfileInfo(Profile);
}
示例9: InsertUpdateFromMaster
public void InsertUpdateFromMaster(ArrayList From)
{
CRM.DataAccess.AdministratorEntity.FromMasterStoredProcedure objfrom = new CRM.DataAccess.AdministratorEntity.FromMasterStoredProcedure();
From.Insert(3, Session["usersid"].ToString());
objfrom.InsertUpdateFromMaster(From);
}
示例10: Main
static void Main(string[] args)
{
ArrayList a = new ArrayList();
a.Add(123);
a.Add("BARD");
a.Add(34.689);
a.Insert(2, 'A');
a.Remove(123);
a.RemoveAt(2);
foreach (Object o in a)
{
Console.WriteLine(o.ToString());
}
//Student s = new Student();
//s.GetData();
//a.Add(s);
//foreach (Object o in a)
//{
// if (o.GetType().ToString() == "ArrayListSample.Student")
// {
// Student s1 = (Student)o;
// s1.ShowData();
// }
//}
//Console.WriteLine("No of elements are:" +a.Count);
Console.Read();
}
示例11: InsertUpdateEmailConfig
public void InsertUpdateEmailConfig(ArrayList Config)
{
CRM.DataAccess.AdministratorEntity.EmailConfigStoredProcedure objemailConfig = new CRM.DataAccess.AdministratorEntity.EmailConfigStoredProcedure();
Config.Insert(5, Session["usersid"].ToString());
objemailConfig.InsertUpdateEmailConfig(Config);
}
示例12: SaveButton_Click
private void SaveButton_Click(object sender, EventArgs e)
{
if (SubjectBox.Text.Length == 0)
{
MessageBox.Show("Cannot proceed with empty name");
return;
}
ArrayList list = new ArrayList((string[])Host.SubjectList.DataSource);
list.Sort();
int id = list.BinarySearch(SubjectBox.Text);
if (id >= 0)
{
MessageBox.Show("Subject with that name already exists!");
return;
}
id = ~id;
list.Insert(id, SubjectBox.Text);
string[] n = new string[list.Count];
list.CopyTo(n);
Host.SubjectBox2.AutoCompleteCustomSource.Add(SubjectBox.Text);
Host.SubjectList.DataSource = n;
Host.RenewSubjectList();
Host.SubjectList.SelectedItem = SubjectBox.Text;
this.Close();
}
示例13: button3_Click
private void button3_Click(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(10);
arr.Add(20); //To add a new element at the end of collection
arr.Add(30);
arr.Add(40);
arr.Add(50);
arr.Add(60);
arr.Add(70);
arr.Add(80);
arr.Add(90);
arr[3] = 400; //To overwrite the value
MessageBox.Show(arr.Capacity.ToString());
arr.Insert(3, 1000);//insert in the middle
//shift the other elements =>index,value
foreach (object obj in arr)
{
listBox3.Items.Add(obj.ToString());
}
arr[12] = 10; //Runtime error
arr.Remove(10); //remove 10 <=value
arr.RemoveAt(1); //remove element at index 1 <=index
}
示例14: AddCheckBoxColumn
protected virtual ArrayList AddCheckBoxColumn(ICollection columnList)
{
ArrayList list = new ArrayList(columnList);
// Determine the check state for the header checkbox
string shouldCheck = "";
string checkBoxID = String.Format(CheckBoxColumHeaderID, ClientID);
string checkBoxName = String.Format(CheckBoxColumHeaderName, UniqueID);
if (IsTitleCheckBoxChecked)
shouldCheck = "checked=\"checked\"";
// Create a new custom CheckBoxField object
InputCheckBoxField field = new InputCheckBoxField(RowIdPropertyName);
field.ItemStyle.Width = new Unit("16px");
field.HeaderText = String.Format(CheckBoxColumHeaderTemplate, checkBoxID, checkBoxName, shouldCheck, ClientJSObjectName);
field.ReadOnly = true;
// Insert the checkbox field into the list at the specified position
if (CheckBoxColumnIndex > list.Count)
{
// If the desired position exceeds the number of columns
// add the checkbox field to the right. Note that this check
// can only be made here because only now we know exactly HOW
// MANY columns we're going to have. Checking Columns.Count in the
// property setter doesn't work if columns are auto-generated
list.Add(field);
CheckBoxColumnIndex = list.Count - 1;
}
else
list.Insert(CheckBoxColumnIndex, field);
// Return the new list
return list;
}
示例15: 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());
}
}