2013-03-12 21 views
5

Che è un equivalente di Visual basic 'vbNullChar" in C#cos'è un equivalente vbNullChar in C#?

voglio replicare questa dichiarazione VB in C#

Dim sVersion As String 
sVersion = New String(vbNullChar, 255) 
+2

http: // www .pressthered.com/working_with_null_characters_in_c_net/ –

risposta

15

ho il sospetto che si desidera:?

string sVersion = new string('\0', 255); 

(Questo sembra Vorrei provare a fare un passo indietro e vedere se non c'è un approccio più appropriato al problema più grande.)

+1

+1 per l'avvertenza. – jbabey

+0

Attualmente sto convertendo un'applicazione Vb.net in C# .net dove ho trovato questa affermazione che devo scrivere così com'è .. –

+2

D'accordo sul fatto che dovresti guardare a ciò che stai cercando di ottenere piuttosto che semplicemente convertire il codice - altrimenti potresti anche generare il C# dal codice IL. –

3

Jon Skeet è corretta ...

Inoltre è possibile ottenere questa cosa da qui di seguito il metodo ...

prima Way

char vbNullChar = Convert.ToChar(0);//C# Equivalent to vbNullChar 
string sVersion = new string(vbNullChar, 255); 

secondo Way

char vbNullChar = Convert.ToChar(0x0);//C# Equivalent to vbNullChar 
string sVersion = new string(vbNullChar, 255); 
+0

Non hai bisogno di 'Convert.ToChar' - solo' char vbNullChar = (char) 0; 'funzionerà bene, o' char vbNullChar = '\ 0'; ' –