0

Equal sign isn't working on object creation C#

Here is my error ./Playground/file0.cs(283,14): error CS1519: Invalid token '=' in class, struct, or interface member declaration here is my code class Bullet { public int dmg; public int speed; } Bullet AK = new Bullet(); AK.dmg = 10: AK.speed = 100;

7th Apr 2023, 11:11 PM
C00LD0WN
C00LD0WN - avatar
2 ответов
+ 6
AK.dmg = 10 ; // semicolon
7th Apr 2023, 11:37 PM
SoloProg
SoloProg - avatar
+ 2
your code looks fine but make sure: 1_ Bullet class is outside the program class 2_ the class is public (add a public access specifier behind the keyword class) 3_ if the classes are in different namespaces, add the name space of the Bullet class in the Program class (using yourBulletClassNameSpace) other than that there arent any potential causes for this error i believe oh and the following lines are not really issues but i think its still worth mentioning them 1_ it's generally better to use properties instead of fields for damage and speed since you can define logic for getting and setting their values (like public int Speed { get; set; }, read more on properties here: https://www.w3schools.com/cs/cs_properties.php) 2_ properties should be named with Pascal case (like PascalCase) naming convention and fields with Camel case (like camelCase)
7th Apr 2023, 11:38 PM
Zayn