PowerZox
PowerZox
CC#
Created by PowerZox on 2/10/2025 in #help
Parameterless constructor in struct
public struct MyStruct
{
public int id;
static int count = 0;

public MyStruct() //Not allowed?
{
id = count++;
}
}
public struct MyStruct
{
public int id;
static int count = 0;

public MyStruct() //Not allowed?
{
id = count++;
}
}
Then public MyStruct[] myStruct = new MyStruct[100]; should call the MyStruct() constructor 100 times. How can I do this?
14 replies
CC#
Created by PowerZox on 2/10/2025 in #help
Can I initialize and instance of an object in an array with its index in the array?
Below is what I want to achieve. Thanks in advance for the help. I'm a beginner so sorry if this is a very missworded question
public class MyClass
{
public MyStruct[] structArray = new MyStruct[10];
print(MyStruct[n].id);
}

public struct MyStruct
{
public int id;

public MyStruct(int i)
{
id = i; // Make `id` equal to the index of this instance in `structArray`
}
}
public class MyClass
{
public MyStruct[] structArray = new MyStruct[10];
print(MyStruct[n].id);
}

public struct MyStruct
{
public int id;

public MyStruct(int i)
{
id = i; // Make `id` equal to the index of this instance in `structArray`
}
}
And then MyStruct[n].id would equal n and it would print n.
2 replies
CC#
Created by PowerZox on 8/28/2024 in #help
Easy to use C# audio library for spectrum analyzer?
No description
8 replies