本文整理汇总了C#中System.Collections.Generic.List.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.CopyTo方法的具体用法?C# System.Collections.Generic.List.CopyTo怎么用?C# System.Collections.Generic.List.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUser
private void AddUser()
{
string newUserName = txtNewUserUserName.Text;
string newUserPassword1 = txtNewUserPassword1.Text;
string newUserPassword2 = txtNewUserPassword2.Text;
if (newUserPassword1 != newUserPassword2)
throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Passwords_Not_Matching_Error);
// Step 1: Create the user account.
string email = txtNewUserEmail.Text;
if ((String.IsNullOrEmpty(email)) && (HelperFunctions.IsValidEmail(newUserName)))
{
// No email address was specified, but the user name happens to be in the form of an email address,
// so let's set the email property to the user name
email = newUserName;
}
// Create the user. Any number of exceptions may occur; we'll deal with them in a catch block in the calling method.
Membership.CreateUser(newUserName, newUserPassword1, email);
// Step 2: Add roles to user.
System.Collections.Generic.List<string> selectedRoleNames = new System.Collections.Generic.List<string>();
foreach (ListItem roleItem in cblAvailableRolesForNewUser.Items)
{
if (roleItem.Selected)
{
selectedRoleNames.Add(roleItem.Value);
}
}
if (selectedRoleNames.Count == 0)
throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Create_User_No_Role_Selected_Msg);
string[] roleNames = new string[selectedRoleNames.Count];
selectedRoleNames.CopyTo(roleNames);
Roles.AddUserToRoles(newUserName, roleNames);
}
示例2: GetSelectedRolesForNewUser
private string[] GetSelectedRolesForNewUser()
{
//// Step 2: Add roles to user.
System.Collections.Generic.List<string> selectedRoleNames = new System.Collections.Generic.List<string>();
foreach (ListItem roleItem in cblAvailableRolesForNewUser.Items)
{
if (roleItem.Selected)
{
selectedRoleNames.Add(roleItem.Value);
}
}
if (selectedRoleNames.Count == 0)
throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Create_User_No_Role_Selected_Msg);
string[] roleNames = new string[selectedRoleNames.Count];
selectedRoleNames.CopyTo(roleNames);
return roleNames;
}
示例3: ListRNDTest
public void ListRNDTest()
{
var controlList = new System.Collections.Generic.List<int>();
var testList = new MyList<int>();
var r = new System.Random();
for (int i = 0; i < 1000; i++)
{
var next = r.Next();
controlList.Add(next);
testList.Add(next);
Assert.AreEqual(controlList.Count, testList.Count);
}
for (int i = 0; i < 1000; i++)
{
Assert.IsTrue(testList.IndexOf(controlList[i]) == i);
}
for (int i = 0; i < controlList.Count; i++)
{
if (r.Next() < int.MaxValue / 2)
{
testList.RemoveAt(i);
controlList.RemoveAt(i);
}
else
{
var newItem = r.Next();
testList.Insert(i, newItem);
controlList.Insert(i, newItem);
}
}
Assert.AreEqual(controlList.Count, testList.Count);
foreach (var itm in controlList){
Assert.IsTrue(testList.Contains(itm));
}
for (int i = 0; i < controlList.Count / 2; i++ )
{
var e = controlList[i];
controlList.Remove(e);
testList.Remove(e);
}
int[] controllarray = new int[controlList.Count+1];
int[] testArray = new int[testList.Count+1];
controllarray[0] = r.Next();
testArray[0] = controllarray[0];
controlList.CopyTo(controllarray, 1);
testList.CopyTo(testArray, 1);
var q = from a in testArray
join b in controllarray on a equals b
select a;
Assert.IsTrue(testArray.Length == controllarray.Length && q.Count() == controllarray.Length);
controlList.Clear();
testList.Clear();
Assert.AreEqual(controlList.Count,testList.Count);
}