本文整理汇总了C#中System.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# System.ToArray方法的具体用法?C# System.ToArray怎么用?C# System.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertSortTest
public void InsertSortTest()
{
// Random elements
var sorter = new InsertionSort<int>();
sorter.Sort(shuffledList);
var temp = shuffledList.ToArray();
Array.Sort(temp);
CollectionAssert.AreEqual(temp, shuffledList);
//one element
var collection = new[] {0};
sorter.Sort(collection);
temp = collection.ToArray();
Array.Sort(temp);
CollectionAssert.AreEqual(temp, collection);
//zero elements
collection = new int[0];
sorter.Sort(collection);
temp = collection.ToArray();
Array.Sort(temp);
CollectionAssert.AreEqual(temp, collection);
//null elements
collection = null;
sorter.Sort(collection);
CollectionAssert.AreEqual(null, collection);
}
示例2: GetStandardValues
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
var standardValues = new[] { NullLifetimeManagerDisplay }
.Union(LifetimeManagerTypes.Select(x => x.Name))
.Union(new[] {DesignResources.RegistrationLifetimeCustom});
return new StandardValuesCollection(standardValues.ToArray());
}
示例3: Set
public void Set(object target, object value, params object[] index)
{
IEnumerable<object> args = new[] { value };
if (index != null) args = args.Union(index);
if (target != null && !target.GetType().CanAssign(InternalMember.DeclaringType))
throw new TargetException("Expected {0}".AsFormat(InternalMember.DeclaringType.GetRealClassName()));
Cache.GetSetter(InternalMember)(target, args.ToArray());
}
示例4: BinaryToImage
public static Image BinaryToImage(System.Data.Linq.Binary binaryData)
{
if (binaryData == null) return null;
byte[] buffer = binaryData.ToArray();
MemoryStream memStream = new MemoryStream();
memStream.Write(buffer, 0, buffer.Length);
return Image.FromStream(memStream);
}
示例5: Union
public Tree Union(Tree t, Edge e)
{
var es = new[] { e };
es = es.Concat(Edges).ToArray();
es = es.Concat(t.Edges).ToArray();
var ns = Nodes.Concat(t.Nodes);
return new Tree(ns.ToArray(), es.ToArray());
}
示例6: Pipe
public PvcPipe Pipe(string tag, Func<IEnumerable<PvcStream>, IEnumerable<PvcStream>> plugin)
{
IEnumerable<string> tags = new[] { tag };
if (tag.IndexOf(',') != -1)
{
tags = tag.Split(',').ToList().Select(x => x.Trim());
}
return this.Pipe(tags.ToArray(), plugin);
}
示例7: CanSortDates
public void CanSortDates()
{
var sourceArray = new[] { DateTime.MaxValue, DateTime.MinValue, DateTime.Now };
var expected = sourceArray.ToArray();
Array.Sort(expected);
var sorter = DedicatedSortersFactory.CreateDedicatedSorter<DateTime>();
sorter.Sort(sourceArray);
CollectionAssert.AreEqual(expected, sourceArray);
}
示例8: CanSortDoubles
public void CanSortDoubles()
{
var sourceArray = new[] { 10.1, 20.2, 1.343, -4.121, 5.23, 6.5, 11.77, 3443.23 };
var expected = sourceArray.ToArray();
Array.Sort(expected);
var sorter = DedicatedSortersFactory.CreateDedicatedSorter<double>();
sorter.Sort(sourceArray);
CollectionAssert.AreEqual(expected, sourceArray);
}
示例9: LoadChildNodes
public void LoadChildNodes(TreeNode node, System.Collections.Generic.IList<TreeNode> nodes)
{
tableNodeContainer.BeforeExpand -= tableNodeContainer_BeforeExpand;
node.Nodes.Clear();
node.Nodes.AddRange(nodes.ToArray());
node.Expand();
ShowReady();
tableNodeContainer.BeforeExpand += tableNodeContainer_BeforeExpand;
}
示例10: CanSortFloats
public void CanSortFloats()
{
var sourceArray = new[] { 10.1f, 20.2f, 1.343f, -4.121f, 5.23f, 6.5f, 11.77f, 3443.23f };
var expected = sourceArray.ToArray();
Array.Sort(expected);
var sorter = DedicatedSortersFactory.CreateDedicatedSorter<float>();
sorter.Sort(sourceArray);
CollectionAssert.AreEqual(expected, sourceArray);
}
示例11: CanSortIntegers
public void CanSortIntegers()
{
var sourceArray = new[] { 10, 20, 1, -4, 5, 6, 11, 3443 };
var expected = sourceArray.ToArray();
Array.Sort(expected);
var sorter = DedicatedSortersFactory.CreateDedicatedSorter<int>();
sorter.Sort(sourceArray);
CollectionAssert.AreEqual(expected, sourceArray);
}
示例12: XOR_AllTrue_Multiple
public void XOR_AllTrue_Multiple()
{
// Arrange
bool result;
var inputs = new[] { true, true, true };
IConditionModifier modifier = new XORModifier();
// Act
result = modifier.IsConditionMet(true, inputs.ToArray());
// Assert
Assert.IsFalse(result);
}
示例13: Main
static void Main(string[] args)
{
var names = new[] { "Bessie", "Vashti", "Frederica", "Nisha", "Kendall", "Magdalena", "Brendon", "Eve", "Manda", "Elvera", "Miquel", "Tyra", "Lucie", "Marvella", "Tracee", "Ramiro", "Irene", "Davina", "Jeromy", "Siu" };
//1
Console.WriteLine("Create a list of Persons, each with one of the names");
foreach (string s in (string[])names.ToArray())
{
Console.WriteLine(s);
}
//2
Console.WriteLine("Create the same list then get a subset with only people whose names start with M");
var mStarts = from s in names.ToList() where s.StartsWith("M") select s;
foreach (string s in (string[])mStarts.ToArray())
{
Console.WriteLine(s);
}
//3
Console.WriteLine("Create the same list then get a list everyone’s names in uppercase ");
var upper = names.Select(x => x.ToUpper()).ToArray();
foreach (string s in (string[])upper.ToArray())
{
Console.WriteLine(s);
}
//4
Console.WriteLine("Create the same list then get a and array if int with the length of each name");
foreach (string s in (string[])names.ToArray())
{
Console.WriteLine(s + " --> " + s.Length);
}
//5
Console.WriteLine("Create the same list then get a list with only the name shortened to the first three letters ordered by name");
var strfirst3charorder = names.Select(x => x.Substring(0, 3)).OrderBy(x => x);
foreach (string s in (string[])strfirst3charorder.ToArray())
{
Console.WriteLine(s);
}
Console.ReadLine();
}
示例14: Save
public void Save(string file, System.IO.MemoryStream contents)
{
using (System.IO.IsolatedStorage.IsolatedStorageFile isoStorage = GetISOStorage())
{
using (var writer = new System.IO.IsolatedStorage.IsolatedStorageFileStream(file, System.IO.FileMode.Create, isoStorage))
{
if (contents.CanSeek && contents.Position > 0) contents.Seek(0, SeekOrigin.Begin);
byte[] data = contents.ToArray();
writer.Write(data, 0, data.Length);
writer.Close();
}
}
}
示例15: Save
public async Task<bool> Save(string file, System.IO.MemoryStream contents)
{
byte[] data = contents.ToArray();
var folder = ApplicationData.Current.LocalFolder;
var f = await folder.CreateFileAsync(file, CreationCollisionOption.ReplaceExisting);
using (var s = await f.OpenStreamForWriteAsync())
{
await s.WriteAsync(data, 0, data.Length);
}
return true;
}