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.
Created
September 18, 2019 20:40
-
-
Save tarrball/6ac0e6f16ef8232a67ebc0a2b3618a98 to your computer and use it in GitHub Desktop.
C# - Creating an empty array of things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
What is the time/space complexity of this algorithm?