At school we are currently learning GitHub
and are therefore programming C#
, which I learned last year. In the meantime, however, I have forgotten some things. Task, I have to create 2 methods:
A static bool LoadConfig method (ref int number): Here the standard configuration file config.ini is read out and the number is returned. Should the file do not exist or do not contain a number, the number 0 is returned and a return value false. Otherwise the return value is true.
One method static bool SaveConfig (int number): Here the standard configuration file config.ini is created or changed and the number entered. Should the If the file cannot be created, a return value is returned false. Otherwise the return value is true.
Code:
static bool SaveConfig(int number)
{
var path = @"C:\Users\KarDan02\Desktop\Collide_d\Coll_1_ide";
string text = Convert.ToString(number);
File.WriteAllText(path, text);
if (File.Exists(path))
{
return true;
}
else
{
return false;
}
}
public static bool LoadConfig(ref int number)
{
var path = @"C:\Users\KarDan02\Desktop\config.ini";
string numbertext = File.ReadAllText(path);
int controll = Convert.ToInt32(numbertext);
if ((File.Exists(pfad)) & (controll> 0))
{
number = controll;
return true;
}
else
{
number = 0;
return false;
}
}
Problems: A) The path can only be used by you. Could you do it so that the .ini file is saved and read into the current directory of the program? How do you create a dynamic location? Because it actually depends on the user in which folder he initializes the Github file. Or can you possibly save it in the C # storage location or the location where the project is?
B) You change the value of number in any case (even if the ini file has a 0 in it).