.Substring()

Non sto a spiegare cosa fa perchè tutti l'avranno usato molte volte.

Il primo parametro indica l'indice 0-based da cui partire. Il comportamento che non mi aspettavo è che l'indice può arrivare alla Length della stringa senza sollevare eccezioni.

[C#]
String myString = "abc";
bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.


Technorati tags:

Print | posted @ sabato 17 aprile 2010 14:55

Comments have been closed on this topic.