0

Hello everyone :) I lately started learning C# and wanted to create minesweeper game. I had pattern, done before in C++ and Java ( just console ) and it seemed to be fine in C# as well.

But there is an error I can't get rid of.

Warning CS0649 Field 'Minefield.field' is never assigned to, and will always have its default value null

Here is part of code I have trouble with:

 struct  Field
{
    public int mine;
    public int mines_around;
    public State status;

};

class Minefield
{
    Random rand = new Random();
    const int Rows = 10;
    const int Columns = 10;
    Field[][] field;
    int Difficulty;

    public Minefield(int Diff)//from 1 to 10

I've seen there is way of creating arrays like Field[,] field = new Field[10,10] But as I tried it the same error occured. Any ideas from more experienced C# programmers ?

haxpiotr
  • 1
  • 1
  • Since it's not a `Field[,]`, but a `Field[][]`, perhaps `Field[][] field = new Field[10][10];` could be the way to go? – cbr May 15 '16 at 10:03
  • Also, you might be interested in learning [the difference between a `Field[,]` and a `Field[][]`](http://stackoverflow.com/q/597720/996081). – cbr May 15 '16 at 10:04
  • It is not an error (just a warning). I am sure if you start using the field (accessing the value somewhere) the warning will disappear. – JanDotNet May 15 '16 at 10:05

1 Answers1

0

It is not an error, but simply notice from the static code analysis. It will disappear as soon as you use it, e.g. by assigning values or reading them.

Keep in mind while struct is a value type an array of structs is not. Therefore unline private int a it is not assigned automatically.

Toxantron
  • 2,218
  • 12
  • 23