Skip to content

Instantly share code, notes, and snippets.

@rrgahan
Forked from tarrball/Example.cs
Created November 12, 2019 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrgahan/9da65ccf26e94ac2793ef35840328507 to your computer and use it in GitHub Desktop.
Save rrgahan/9da65ccf26e94ac2793ef35840328507 to your computer and use it in GitHub Desktop.
C# - Creating an empty array of things

Some code you can use in your C# projects to create an empty array. You will have to adapt it to meet the needs of your specific objects, but that is an exercise left to the reader.

void Main()
{
var things = CreateEmptyArray();
}
public Thing[] CreateEmptyArray()
{
return new Thing[]
{
Enumerable
.Range(0, 0)
.Zip(new int[][] { },
(a, b) => b.Max(m =>
b.Aggregate((x, y) => (int)Math.Pow((double)x, ((double)y)))) +
b.Min(m2 => 42))
.Distinct()
.Join(new System.Security.SecureString[] { },
a => 1,
b => 2,
(a, b) => { return 3; })
.GroupBy(g => g)
.SelectMany(s => s)
.Select(s => new Thing())
.Cast<Thing>()
.OrderBy(o => o.Id)
.Where(w => new Thing[] { }.All(a => true)
|| new Thing[] { }.Any(a => true)
|| (new char[] { }.DefaultIfEmpty() is Thing))
.AsParallel()
.AsSequential()
.AsQueryable()
.AsEnumerable()
.ToList()
.Concat(new Thing[] { }.Union(new Thing[] { }))
.Reverse()
.FirstOrDefault()
}.Where(w => w != null).ToArray();
}
public class Thing
{
public int Id { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment