TheHelpfulHelper
TheHelpfulHelper
CC#
Created by TheHelpfulHelper on 5/4/2024 in #help
✅ Conversions of types between two libraries
So I have two libraries (A and B) which both have their own Vector3 structs and in my project I want to pass them back and forth, because the libraries offer different functionality that uses the Vector3s. Do I have to create an intermediary representation that implements implicit conversions in both directions or is there a better way? A round-trip would look like this currently: LibA.Vector3 > MyCode.Vector3 > LibB.Vector3 > MyCode.Vector3 > LibA.Vector3 Not just does this create a lot of boiler-platey code if I have to do it for all of the other Mathematical structs (Vector2, Vector4, Quaternion, Matrix3x3, Matrix4x4 etc.) but it also seems kinda wasteful, if it actually has to allocate memory for each cast which is pretty much immediately discarded again...
23 replies
CC#
Created by TheHelpfulHelper on 2/21/2023 in #help
❔ LINQ: Group and extract all consecutive elements from List that match predicate
Example:
List<int> ints = new() {6,3,1,1,1,1,1,2,7,8,1,1,1,1,3,2,5,1,1,9,8,1,1,1,1,4,7,8,1}
var output = ints.GroupConsecutive().Where((g) => g.Key == 1); // Not a real function

foreach (var o in output)
{
Console.WriteLine(o.Count);
}
List<int> ints = new() {6,3,1,1,1,1,1,2,7,8,1,1,1,1,3,2,5,1,1,9,8,1,1,1,1,4,7,8,1}
var output = ints.GroupConsecutive().Where((g) => g.Key == 1); // Not a real function

foreach (var o in output)
{
Console.WriteLine(o.Count);
}
Expected output:
5
4
2
4
1
5
4
2
4
1
Is there such functionality in LINQ?
78 replies
CC#
Created by TheHelpfulHelper on 12/12/2022 in #help
✅ How do I merge a list of dictionaries based on keys using LINQ?
So if I have something like: [{ number: 1 }, { number: 2 }, { number: 3 }] I want to get: { number: [1, 2, 3]} I allow duplicates.
17 replies