Autor Beitrag
friesi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Windows XP SP2
VS 2005
BeitragVerfasst: Di 14.11.06 14:51 
Hallo!

Ich habe eine Variable dir vom Typ string.
Ich möchte prüfen ob diese "leer" ist.

ausblenden C#-Quelltext
1:
2:
3:
if (dir == null) {
 // mache das
}


Damit geht es nicht. In PHP gibt es die Funktion "empty", gibt es bei C# etwas ähnliches?

Gruss,
Friesi
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 14.11.06 14:55 
Bei Deiner Abfrage würde true nur rauskommen, wenn das Objekt noch gar nicht existiert. Du musst schon auf einen leeren String prüfen:
ausblenden C#-Quelltext
1:
2:
3:
if (dir.Equals("")) ...
//oder
if (dir == "") ...
friesi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Windows XP SP2
VS 2005
BeitragVerfasst: Di 14.11.06 15:02 
Ok danke!
Das hat meine Frage schon beantwortet :)
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 14.11.06 15:15 
user profile iconUGrohne hat folgendes geschrieben:
Bei Deiner Abfrage würde true nur rauskommen, wenn das Objekt noch gar nicht existiert. Du musst schon auf einen leeren String prüfen:
ausblenden C#-Quelltext
1:
2:
3:
if (dir.Equals("")) ...
//oder
if (dir == "") ...
FxCop wird dir aber zur Sicherheit etwas Anderes vorschlagen ;) : String.IsNullOrEmpty.
McSteel
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 54

Win XP
VS 6.0, VS2005
BeitragVerfasst: Di 14.11.06 15:51 
wer ist FXCOP?
MagicAndre1981
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 14.11.06 18:46 
ein MSTool, das deinen Code analysiert.

Wie Klarabella sagte ist die beste Lösung Suche im MSDN STRING.ISNULLOREMPTY


Zuletzt bearbeitet von MagicAndre1981 am Mi 15.11.06 20:34, insgesamt 1-mal bearbeitet
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 15.11.06 19:52 
Wenn dann bitte auch Giesecke-stilecht mit zwei "l" ;) . Wenn du dafür das "s" von "dass" entfernst, bleibt die Länge des Beitrages sogar gleich *g* .
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Mo 27.11.06 22:35 
user profile iconKhabarakh hat folgendes geschrieben:
Wenn dann bitte auch Giesecke-stilecht mit zwei "l" ;) . Wenn du dafür das "s" von "dass" entfernst, bleibt die Länge des Beitrages sogar gleich *g* .
lol!