c# - A method that returns string value -
i trying create method(that makes labels slide left). i've tried , researched bit , came this.
public static void slidingtext(string a) { string first = a.substring(1, a.length - 1); string second= a.substring(0, 1); = first + second; return a; }
however, when use this(on button etc) :
slidingtext(label1.text);
i nothing. have worked on while , saw can text value of label1
, change in method changed value never goes out of method. missing , still couldn't figure out missing.
regards
there 2 ways of making work:
- change code take
string a
reference, or - change code return
string
.
here first solution (this not work properties):
public static void slidingtext(ref string a) { string first = a.substring(1, a.length - 1); string second= a.substring(0, 1); = first + second; }
here second solution:
public static string slidingtext(string a) { string first = a.substring(1, a.length - 1); string second= a.substring(0, 1); return first + second; }
this require assignment on caller's side.
you can further optimize code make single line of code:
public static string slidingtext(string a) { return a.substring(1) + a[0]; }
Comments
Post a Comment