Hello everybody,
I am going to consider an object to be declared and initialized. Let us assume there are no other properties, that could lead to create a class.
In such case, I have got to declare the object in the class using it, and initialize it in the constructor, maybe via a property.
In this context I shall consider the main() function as a constructor of Program. Oh well, I see that now, by default, the class is named Solution ?
Let us take an example, to come back to the purpose :
class Solution
{
static List<int> listTest;
static void Main(string[] args)
{
listTest = new List<int>();
}
}
and I am not sure this is specific to C#.
Well now, this is why I opened this thread. I wanted to declare a Dictionary<string, int> that way, and an error message alerted me that the object had to be implemented.
So, I had to do it this way :
class Solution
{
static Dictionary<string, int> DictOri = new Dictionary<string, int>();
static Dictionary<int, string> DictNb = new Dictionary<int, string>();
}
In the main(), I can directly use DictOri.Add(), the dictionary is already implemented.
Did you already notice any other object with such particularities ?
I have another question concerning dictionaries, perhaps I should create another thread ?
I need to associate E to 90, S to 180, and then back 90 to E, 180 to S. In such case I create two dictionaries, as in the example I gave.
So I shall have to create a function for the creation of elements, this is why I created the dictionaries at the class level, and not in the main :
static void IniDict(string s, int nb)
{
DictOri.Add(s, nb);
DictNb.Add(nb, s);
}
So, now the question : is there any functionality of the dictionaries I missed, that would allow all this with only one dictionary ?
Well, at a moment I clicked somewhere, I am no more able to say on what, and it made this appear :
Did I do a mess ?
A tooltip on each button would probably have avoided me to ask the question.
Oh sorry, got it : I wanted to modify my message, looked for the pencil button. I found one at the top of the page, but this was to modify the title. So, these buttons I copied were to validate or cancel the modification of the title.
To modify the message it is better to use the pencil down the message.