Moods
Moods
CC#
Created by Moods on 3/22/2024 in #help
Convert to LINQ
How would y'all make this using just LINQ functions?
IEnumerable<string[]> SequenceOfGrids(string[] input)
{
var res = new List<string[]>();

int start = 0;

for(int a = 1; a < input.Length; a++)
{
if(string.IsNullOrWhiteSpace(input[a]))
{
res.Add(input[start..a]);
start = a + 1;
}
}

res.Add(input[start..^0]);

return res;
}
IEnumerable<string[]> SequenceOfGrids(string[] input)
{
var res = new List<string[]>();

int start = 0;

for(int a = 1; a < input.Length; a++)
{
if(string.IsNullOrWhiteSpace(input[a]))
{
res.Add(input[start..a]);
start = a + 1;
}
}

res.Add(input[start..^0]);

return res;
}
basically input is a collection of grids separated by one whitespace line, and i want to transform it into a list of the grids here is a cutout of an example of such a grid
123
456
789

123
456
789
123
456
789

123
456
789
18 replies
CC#
Created by Moods on 2/9/2024 in #help
how Int32 etc. store their values
So we know that stuff like Int and long is just a sequence of bits with the length depending on the data type. I wanted to know at what level is this conversion to binary being done like if I have
int foo = 90;
Console.WriteLine(foo);
int foo = 90;
Console.WriteLine(foo);
To my knowledge this 90 is converted to its 32-bit binary equivalent and stored then, and when you’d want to read from that variable (I’m assuming correct me if I’m wrong) this binary is then converted to its decimal equivalent and then displayed with the WriteLine function. I just wanted to know is this conversion done at a hardware level (like how processors have instructions built in) or is it done by the compiler. And what of the case with negative numbers because those have to be stored as two’s complements too
15 replies
CC#
Created by Moods on 4/10/2023 in #help
with or without ref
so i learned that in c#(or most oop languages) when you create a method that takes an object as a parameter, and you call said method and pass an object of the same type as an argument, it passes the reference to the caller. so if you were to alter any properties of the object parameter in the method, it affects the object that was used as a parameter something like
void ChangeName(Person p) {
p.Name = "Alice";
}

Person person = new Person();
person.Name = "Bob";
ChangeName(person);
void ChangeName(Person p) {
p.Name = "Alice";
}

Person person = new Person();
person.Name = "Bob";
ChangeName(person);
i assume that after the last statement person's Name property is now "Alice". i was reading up the docs and it mentioned you would use ref before an object parameter if you wanted to alter the original object argument and I'm confused cus isnt this how objects already worked like..?
9 replies