本文整理汇总了C#中Collection.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.CopyTo方法的具体用法?C# Collection.CopyTo怎么用?C# Collection.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encode
public byte[] Encode()
{
Collection<byte> collection1 = new Collection<byte>();
collection1.Add(100);
ArrayList list1 = new ArrayList();
foreach (string text1 in dict.Keys)
{
list1.Add(text1);
}
foreach (string text2 in list1)
{
ValueString text3 = new ValueString(text2);
foreach (byte num1 in text3.Encode())
{
collection1.Add(num1);
}
foreach (byte num2 in dict[text2].Encode())
{
collection1.Add(num2);
}
}
collection1.Add(0x65);
byte[] buffer1 = new byte[collection1.Count];
collection1.CopyTo(buffer1, 0);
return buffer1;
}
示例2: Main
private static void Main()
{
ICollection<string> myCole = new Collection<string>(); //Initializing a collection of strings
myCole.Add("Takane"); //Adding elements on a collection
myCole.Add("Sena");
myCole.Add("Masuzu");
myCole.Add("Yusa Emi");
foreach(string b in myCole){
Console.WriteLine("myCole contains " + b);
}
myCole.Remove("Yusa Emi"); //removing an element on a collection
Console.WriteLine("Deleted an element");
bool a = myCole.Contains("Takane"); //tells whether the collection contains a certain element
//enumerate the elements
foreach(string b in myCole){
Console.WriteLine("myCole contains " + b);
}
//copying the content of a collection to an array
string[] c = new string[myCole.Count]; // initializes the array with the size equal to myCole
myCole.CopyTo(c, 0); //Copy to string array c from element 0
foreach(string d in c){
Console.WriteLine("String Copy in c: {0}", d);
}
}
示例3: GetTypesWithClassAttribute
private static Type[] GetTypesWithClassAttribute(Assembly asm)
{
Type[] types = asm.GetTypes();
Collection<Type> classTypes = new Collection<Type>();
foreach (Type t in types)
{
//Console.WriteLine("type:" + t.Name);
Type tAtt = typeof(ClassAttribute);
ClassAttribute a = (ClassAttribute)Attribute.GetCustomAttribute(t, tAtt);
if (a != null)
{
//Console.WriteLine("Are clasa: " + a.Name);
classTypes.Add(t);
}
}
Type[] classTypesArray = new Type[classTypes.Count];
classTypes.CopyTo(classTypesArray, 0);
return classTypesArray;
}
示例4: RssCategory
/// <summary>
/// Initializes a new instance of the <see cref="RssCategory"/> class using the supplied <see cref="Collection{T}"/>.
/// </summary>
/// <param name="value">A collection of strings that describe the hierarchical position in the taxonomy. The order of collection elements determines the taxonomy hierarchy.</param>
/// <exception cref="ArgumentNullException">The <paramref name="value"/> is a null reference (Nothing in Visual Basic).</exception>
public RssCategory(Collection<string> value)
{
//------------------------------------------------------------
// Validate parameter
//------------------------------------------------------------
Guard.ArgumentNotNull(value, "value");
//------------------------------------------------------------
// Build slash-delimited string for supplied taxonomy hierarchy
//------------------------------------------------------------
if (value.Count > 0)
{
string[] hierarchy = new string[value.Count];
value.CopyTo(hierarchy, 0);
this.Value = String.Join("/", hierarchy);
}
}
示例5: UpdateEmail
/// <summary>
/// Update email
/// </summary>
/// <param name="collectionId">The collectionId of the folder which contains the item to be updated.</param>
/// <param name="syncKey">The syncKey which is returned from server</param>
/// <param name="read">The value is TRUE indicates the email has been read; a value of FALSE indicates the email has not been read</param>
/// <param name="serverId">The server id of the email</param>
/// <param name="flag">The flag instance</param>
/// <param name="categories">The array of categories</param>
/// <returns>Return update email result</returns>
protected SyncStore UpdateEmail(string collectionId, string syncKey, bool? read, string serverId, Request.Flag flag, Collection<string> categories)
{
Request.SyncCollectionChange changeData = new Request.SyncCollectionChange
{
ServerId = serverId,
ApplicationData = new Request.SyncCollectionChangeApplicationData()
};
List<object> items = new List<object>();
List<Request.ItemsChoiceType7> itemsElementName = new List<Request.ItemsChoiceType7>();
if (null != read)
{
items.Add(read);
itemsElementName.Add(Request.ItemsChoiceType7.Read);
}
if (null != flag)
{
items.Add(flag);
itemsElementName.Add(Request.ItemsChoiceType7.Flag);
}
if (null != categories)
{
Request.Categories2 mailCategories = new Request.Categories2 { Category = new string[categories.Count] };
categories.CopyTo(mailCategories.Category, 0);
items.Add(mailCategories);
itemsElementName.Add(Request.ItemsChoiceType7.Categories2);
}
changeData.ApplicationData.Items = items.ToArray();
changeData.ApplicationData.ItemsElementName = itemsElementName.ToArray();
SyncRequest syncRequest = TestSuiteHelper.CreateSyncChangeRequest(syncKey, collectionId, changeData);
SyncStore result = this.EMAILAdapter.Sync(syncRequest);
Site.Assert.AreEqual<byte>(
1,
result.CollectionStatus,
"The server returns a Status 1 in the Sync command response indicate sync command success.");
return result;
}
示例6: GetNewFiles
private string[] GetNewFiles()
{
//TODO: weed out large files
//TODO: ingore previous
string[] r = Directory.GetFiles(from);//, "*.ZomBarchive????");
Collection<string> c = new Collection<string>();
foreach (string item in r)
{
if (!item.Contains(".ZomBarchive"))
c.Add(item);
}
r = new string[c.Count];
c.CopyTo(r, 0);
return r;
}
示例7: CombineSources
/// <summary>
/// combine the sources of BindingExpressions, using new sources for
/// the BindingExpression at the given index
/// </summary>
/// <param name="index">-1 to indicate no new sources</param>
/// <param name="bindingExpressions">collection of child binding expressions </param>
/// <param name="count">how many child expressions to include</param>
/// <param name="newSources">use null when no new sources</param>
/// <returns></returns>
internal static WeakDependencySource[] CombineSources(int index, Collection<BindingExpressionBase> bindingExpressions, int count, WeakDependencySource[] newSources)
{
if (index == count)
{
// Be sure to include newSources if they are being appended
count++;
}
Collection<WeakDependencySource> tempList = new Collection<WeakDependencySource>();
for (int i = 0; i < count; ++i)
{
BindingExpressionBase bindExpr = bindingExpressions[i];
WeakDependencySource[] sources = (i==index) ? newSources :
(bindExpr != null) ? bindExpr.WeakSources :
null;
int m = (sources == null) ? 0 : sources.Length;
for (int j = 0; j < m; ++j)
{
WeakDependencySource candidate = sources[j];
// don't add duplicate source
for (int k = 0; k < tempList.Count; ++k)
{
WeakDependencySource prior = tempList[k];
if (candidate.DependencyObject == prior.DependencyObject &&
candidate.DependencyProperty == prior.DependencyProperty)
{
candidate = null;
break;
}
}
if (candidate != null)
tempList.Add(candidate);
}
}
WeakDependencySource[] result;
if (tempList.Count > 0)
{
result = new WeakDependencySource[tempList.Count];
tempList.CopyTo(result, 0);
tempList.Clear();
}
else
{
result = null;
}
return result;
}
示例8: MSASNOTE_S01_TC07_Sync_ChangeNote_Categories
public void MSASNOTE_S01_TC07_Sync_ChangeNote_Categories()
{
#region Call method Sync to add a note with two child elements in a Categories element to the server
Dictionary<Request.ItemsChoiceType8, object> addElements = this.CreateNoteElements();
Request.Categories3 categories = new Request.Categories3 { Category = new string[2] };
Collection<string> category = new Collection<string> { "blue category", "red category" };
category.CopyTo(categories.Category, 0);
addElements[Request.ItemsChoiceType8.Categories2] = categories;
this.SyncAdd(addElements, 1);
#endregion
#region Call method Sync to synchronize the note item with the server and expect to get two child elements in response.
// Synchronize the changes with server
SyncStore result = this.SyncChanges(1);
Note noteAdded = result.AddElements[0].Note;
Site.Assert.IsNotNull(noteAdded.Categories, "The Categories element in response should not be null.");
Site.Assert.IsNotNull(noteAdded.Categories.Category, "The category array in response should not be null.");
Site.Assert.AreEqual(2, noteAdded.Categories.Category.Length, "The length of category array in response should be equal to 2.");
#endregion
#region Call method Sync to change the note with MessageClass elements and one child element of Categories element is missing.
Dictionary<Request.ItemsChoiceType7, object> changeElements = new Dictionary<Request.ItemsChoiceType7, object>
{
{
Request.ItemsChoiceType7.MessageClass, "IPM.StickyNote.MSASNOTE1"
}
};
categories.Category = new string[1];
category.Remove("red category");
category.CopyTo(categories.Category, 0);
changeElements.Add(Request.ItemsChoiceType7.Categories3, categories);
SyncStore changeResult = this.SyncChange(result.SyncKey, result.AddElements[0].ServerId, changeElements);
Site.Assert.AreEqual<byte>(
1,
changeResult.CollectionStatus,
"The server should return a Status 1 in the Sync command response indicate sync command succeed.");
#endregion
#region Call method Sync to synchronize the note item with the server, and check if one child element is missing in response.
// Synchronize the changes with server
result = this.SyncChanges(result.SyncKey, 1);
bool isNoteFound = TestSuiteHelper.CheckSyncChangeCommands(result, addElements[Request.ItemsChoiceType8.Subject1].ToString(), this.Site);
Site.Assert.IsTrue(isNoteFound, "The note with subject:{0} should be returned in Sync command response.", addElements[Request.ItemsChoiceType8.Subject1].ToString());
Note note = result.ChangeElements[0].Note;
Site.Assert.IsNotNull(note.Categories, "The Categories element in response should not be null.");
Site.Assert.IsNotNull(note.Categories.Category, "The category array in response should not be null.");
Site.Assert.IsNotNull(note.Subject, "The Subject element in response should not be null.");
Site.Assert.AreEqual(1, note.Categories.Category.Length, "The length of category array in response should be equal to 1.");
bool hasRedCategory = false;
if (note.Categories.Category[0].Equals("red category", StringComparison.Ordinal))
{
hasRedCategory = true;
}
// Add the debug information
Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASNOTE_R10002");
// Verify MS-ASNOTE requirement: MS-ASNOTE_R10002
Site.CaptureRequirementIfIsFalse(
hasRedCategory,
10002,
@"[In Sync Command Response] If a child of the Categories element (section 2.2.2.3) that was previously set is missing, the server will delete that property from the note.");
// Add the debug information
Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASNOTE_R10003");
// Verify MS-ASNOTE requirement: MS-ASNOTE_R10003
Site.CaptureRequirementIfAreEqual<string>(
noteAdded.Subject,
note.Subject,
10003,
@"[In Sync Command Response] The absence of a Subject element (section 2.2.2.6) within an airsync:Change element is not to be interpreted as an implicit delete.");
#endregion
#region Call method Sync to change the note with MessageClass elements and without Categories element.
changeElements = new Dictionary<Request.ItemsChoiceType7, object>
{
{
Request.ItemsChoiceType7.MessageClass, "IPM.StickyNote.MSASNOTE2"
}
};
changeResult = this.SyncChange(result.SyncKey, result.ChangeElements[0].ServerId, changeElements);
Site.Assert.AreEqual<byte>(
1,
changeResult.CollectionStatus,
"The server should return a Status 1 in the Sync command response indicate sync command succeed.");
//.........这里部分代码省略.........
示例9: SetupGuideline
/// <summary>
/// Backup original data and setup guidlines.
/// </summary>
/// <param name="f0s">F0s.</param>
/// <param name="gains">Gains.</param>
/// <param name="durations">Durations.</param>
public void SetupGuideline(
Collection<double> f0s, Collection<double> gains, Collection<double> durations)
{
_f0sGuideline = new double[f0s.Count];
f0s.CopyTo(_f0sGuideline, 0);
_gainsGuideline = new double[gains.Count];
gains.CopyTo(_gainsGuideline, 0);
_durationsGuideline = new double[durations.Count];
durations.CopyTo(_durationsGuideline, 0);
_fNeedResetGuideline = false;
}
示例10: ParseArguments
/// <summary>
/// Parses the arguments.
/// </summary>
/// <param name="arguments">The arguments.</param>
/// <returns></returns>
public static string[] ParseArguments(string arguments)
{
string[] parsedArguments = null;
if (!string.IsNullOrEmpty(arguments))
{
if (arguments.Contains("\""))
{
Collection<string> args = new Collection<string>();
string arg = string.Empty;
bool quoteOpen = false;
for (int i = 0; i < arguments.Length; i++)
{
Char c = arguments[i];
if (c == '"')
{
quoteOpen = !quoteOpen;
}
if (c!= '"' && (c!= ',' || quoteOpen))
{
arg += c;
}
if (!quoteOpen && (c == ',' || i == arguments.Length - 1))
{
args.Add(arg);
arg = string.Empty;
}
}
parsedArguments = new string[args.Count];
args.CopyTo(parsedArguments, 0);
}
else
{
parsedArguments = arguments.Split(',');
}
}
return parsedArguments;
}
示例11: WhereMatches
//.........这里部分代码省略.........
case ColumnType.BOOL:
{
throw new Exception(" >= Test Invalid For Boolean Type.");
}
case ColumnType.DATETIME:
{
if (Convert.ToDateTime(Value) >= Convert.ToDateTime(this[ColumnName]))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.FLOAT:
{
if (((float)Convert.ToDouble(Value)) >= ((float)Convert.ToDouble(this[ColumnName])))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.INTEGER:
{
if (Convert.ToInt64(Value) >= Convert.ToInt64(this[ColumnName]))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.TEXT:
{
if (string.Compare(Convert.ToString(Value), Convert.ToString(this[ColumnName])) >= 0)
cReturnValues.Add(RowIndex);
}break;
}
}
} break;
case ColumnMatchOperation.GreaterThan:
{
if (this[ColumnName] != null)
{
switch (_Table[ColumnName].GetColumnType)
{
case ColumnType.BOOL:
{
throw new Exception(" < Test Invalid For Boolean Type.");
}
case ColumnType.DATETIME:
{
if (Convert.ToDateTime(Value) < Convert.ToDateTime(this[ColumnName]))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.FLOAT:
{
if (((float)Convert.ToDouble(Value)) < ((float)Convert.ToDouble(this[ColumnName])))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.INTEGER:
{
if (Convert.ToInt64(Value) < Convert.ToInt64(this[ColumnName]))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.TEXT:
{
if (string.Compare(Convert.ToString(Value), Convert.ToString(this[ColumnName])) < 0)
cReturnValues.Add(RowIndex);
}break;
}
}
} break;
case ColumnMatchOperation.GreaterThanOrEqualTo:
{
if (this[ColumnName] != null)
{
switch (_Table[ColumnName].GetColumnType)
{
case ColumnType.BOOL:
{
throw new Exception(" <= Test Invalid For Boolean Type.");
}
case ColumnType.DATETIME:
{
if (Convert.ToDateTime(Value) <= Convert.ToDateTime(this[ColumnName]))
cReturnValues.Add(RowIndex); ;
}break;
case ColumnType.FLOAT:
{
if (((float)Convert.ToDouble(Value)) <= ((float)Convert.ToDouble(this[ColumnName])))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.INTEGER:
{
if (Convert.ToInt64(Value) <= Convert.ToInt64(this[ColumnName]))
cReturnValues.Add(RowIndex);
}break;
case ColumnType.TEXT:
{
if (string.Compare(Convert.ToString(Value), Convert.ToString(this[ColumnName])) <= 0)
cReturnValues.Add(RowIndex);
}break;
}
}
} break;
}
}
int[] rValue = new int[cReturnValues.Count];
cReturnValues.CopyTo(rValue, 0);
return rValue;
}
示例12: OrResults
internal static int[] OrResults(int[] Set1, int[] Set2)
{
Collection<int> Results = new Collection<int>();
for (int i = 0; i < Set1.Length; i++)
Results.Add(Set1[i]);
for (int i = 0; i < Set2.Length; i++)
{
bool Found = false;
for (int e = 0; e < Results.Count; e++)
if (Results[e] == Set2[i])
Found = true;
if (!Found)
Results.Add(Set2[i]);
}
int[] rValue = new int[Results.Count];
Results.CopyTo(rValue, 0);
return rValue;
}
示例13: AndResults
internal static int[] AndResults(int[] Set1, int[] Set2)
{
Collection<int> Results = new Collection<int>();
if (Set1.Length > Set2.Length)
{
for (int i = 0; i < Set1.Length; i++)
for (int e = 0; e < Set2.Length; e++)
if (Set1[i] == Set2[e])
Results.Add(Set1[i]);
}
else
{
for (int i = 0; i < Set2.Length; i++)
for (int e = 0; e < Set1.Length; e++)
if (Set2[i] == Set1[e])
Results.Add(Set2[i]);
}
int[] rValue = new int[Results.Count];
Results.CopyTo(rValue, 0);
return rValue;
}
示例14: GetCategoryIdsFromCategoryTitles
public static int[] GetCategoryIdsFromCategoryTitles(Entry entry)
{
int[] categoryIds;
Collection<int> catIds = new Collection<int>();
//Ok, we have categories specified in the entry, but not the IDs.
//We need to do something.
foreach(string category in entry.Categories)
{
LinkCategory cat = Links.GetLinkCategory(category, true);
if(cat != null)
{
catIds.Add(cat.Id);
}
}
categoryIds = new int[catIds.Count];
catIds.CopyTo(categoryIds, 0);
return categoryIds;
}
示例15: ResourcesGet
/// <summary>
/// Gets a collection of all the resources in the data source in pages of data.
/// </summary>
/// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex"/> is zero-based.</param>
/// <param name="pageSize">The size of the page of results to return.</param>
/// <param name="totalRecords">The total number of syndication resources in the data store.</param>
/// <returns>
/// A <see cref="Collection{T}"/> that contains a page of <see cref="ISyndicationResource"/> objects
/// with a size of <paramref name="pageSize"/>, beginning at the page specified by <paramref name="pageIndex"/>.
/// </returns>
private Collection<ISyndicationResource> ResourcesGet(int pageIndex, int pageSize, out int totalRecords)
{
//------------------------------------------------------------
// Local members
//------------------------------------------------------------
Collection<ISyndicationResource> resources = new Collection<ISyndicationResource>();
Collection<ISyndicationResource> pagedResources = new Collection<ISyndicationResource>();
//------------------------------------------------------------
// Load syndication resources from XML data store
//------------------------------------------------------------
DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath);
if (applicationDirectory.Exists)
{
FileInfo[] files = applicationDirectory.GetFiles();
foreach (FileInfo file in files)
{
if (file.Exists)
{
SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension);
if (format != SyndicationContentFormat.None)
{
using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
{
ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(format, stream);
if (resource != null)
{
resources.Add(resource);
}
}
}
}
}
}
//------------------------------------------------------------
// Build paged syndication resources
//------------------------------------------------------------
totalRecords = resources.Count;
if (pageSize > resources.Count)
{
pagedResources = new Collection<ISyndicationResource>(resources);
}
else
{
ISyndicationResource[] array = new ISyndicationResource[resources.Count];
resources.CopyTo(array, 0);
int startIndex = (pageIndex == 0 ? 0 : (pageSize + pageIndex - 1));
for (int i = startIndex; i < pageSize; i++)
{
if(i > array.Length - 1)
{
break;
}
pagedResources.Add(array[i]);
}
}
return pagedResources;
}