C # Implementation of string reverse _c# tutorial

Source: Internet
Author: User

This example for you to share the C # string in reverse order of the implementation code, for your reference, the specific contents are as follows

string concatenation with For loop public string Reversea (string text) {char[] CArray = text.
  ToCharArray ();
  string reverse = String.Empty;
  for (int i = carray.length-1 i >-1; i--) {reverse + = Carray[i];
return reverse; }//Array.reverse function public string Reverseb (string text) {char[] Chararray = text.
  ToCharArray ();
  Array.reverse (Chararray);
return new string (Chararray);
  }//Push/pop stack<> public string reversec (string text) {Stack resultstack = new Stack ();
  foreach (char c in text) {Resultstack.push (c);
  StringBuilder sb = new StringBuilder (); while (Resultstack.count > 0) {sb.
  Append (Resultstack.pop ()); Return SB.
ToString (); //LINQ public string reversed (string text) {return new string (text). ToCharArray (). Reverse ().
ToArray ()); }//StringBuilder public string Reversee (string text) {char[] CArray = text.
  ToCharArray ();
  StringBuilder reverse = new StringBuilder (); for (int i = Carray.leNgth-1; i >-1; i--) {reverse.
  Append (Carray[i]); return reverse.
ToString ();
 }

The above is the entire content of this article, I hope that you learn the C # program to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.