I would like to check a variable beforehand to see whether it is empty or null. If it is null or empty, it should take a character string defined by me. My code:
public string Ergebnis { get; set; }
public string Stufe { get; set; }
public string Niveau { get; set; }
public string Note { get; set; }
public DateTime? Datum { get; set; }
And the function:
public void EndEdit()
{
var newdate = Convert.ToDateTime(Datum).ToShortDateString();
var client = new RestClient("MYDOMAIN");
var request = new RestRequest("SOME THINGS", Method.POST)
.AddUrlSegment("name", Name)
.AddUrlSegment("kompetenzID", KompetenzID)
.AddUrlSegment("ergebnis", Ergebnis)
.AddUrlSegment("stufe", Stufe)
.AddUrlSegment("niveau", Niveau)
.AddUrlSegment("note", Note)
.AddUrlSegment("datum", newdate)
.AddUrlSegment("kuerzel", Kuerzel)
.AddUrlSegment("background", Background)
.AddHeader("Authorization", "Bearer " + ViewFingerPrint);
IRestResponse restResponse = client.Execute(request);
if (restResponse.StatusCode == HttpStatusCode.BadRequest)
{
MessageBox.Show("Der SuS ist nicht in der Datenbank vorhanden.");
}
else
{
}
}
I thought I could do it with an if statement. However, my function then does not recognize the variable. My code:
if (string.IsNullOrEmpty(Ergebnis))
{
string Ergenisneu = "-";
} else
{
string Ergebnisneu = Ergebnis;
}
If I insert the result here:
.AddUrlSegment("ergebnis", Ergebnis)
It does not recognize the variable and says: The variable is never used. How else can I tell the variable that it has a string at null?
The same thing happens in this variant:
if (string.IsNullOrEmpty (Ergebnis))
string Ergebnis= "-";
stringin front of the variable inside theifstatement to use the already existingErgebnisproperty.Ergebnis = string.IsNullOrEmpty (Ergebnis) ? "-" : Ergebnis;