I'm trying to assign an array to an object. Bear with me, but I'm brand new to C# and am slowly getting the hang of it I think. In the program below I've created a class that has two fields: a string (Name) and an array (dimensions). I also have one method called Introduce().
public class Person
{
public string Name;
public int[] dimensions;
public void Introduce()
{
var x = 5;
var y = 7;
Console.WriteLine("Hello my name is " + Name);
Console.WriteLine($"Here we have our calculator class displayed. X + Y equals {Calculator.Add(x, y)}");
//Seeing if it our other file connects to here (Math.cs) it does because we can now use the function Add in here
//We have to specify that the Class is PUBLIC though and then we have to use the using Class.Math or whatever it is
Console.WriteLine($"{Calculator.Add(3, 9)}");
}
}
I've instantiated the Person by creating an object in the Program class. I'm allowed to assign a name, but for some reason it won't let me assign an array. I must have the syntax messed up somehow.
public class Program
{
static void Main(string[] args)
{
var person = new Person();
person.Name = "Jake";
person.Introduce();
person.dimensions = { 10, 9, 10 };
}
}
Again the problem lies with person.dimensions, I'm allowed to create an array in a class but can't use it to assign values in an object?