C # -- 2nd week experiment -- task 7 -- compile a console application -- determine whether the string S refers to is returned (that is, the same string as the reverse read)

Source: Internet
Author: User

/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: determines whether the string S refers to is retrieved (that is, the same string for forward and reverse reads)
* Author: Lei hengxin
* Completion date: January 1, September 09, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
 
[Csharp]
<Span style = "font-size: 24px;"> using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
 
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a program that determines whether the string you entered is a" 文 ");
Console. Write ("Enter the string you want to judge :");
String s = Console. ReadLine ();
Char [] c = s. ToCharArray ();
Int I = c. Length;
Int j = c. Length-1;
Char [] c1 = new char [c. Length];
// Use the foreach statement to output every element in the array cyclically
Foreach (char var in c)
{
C1 [j] = var;
-- J; // reverse string read
}
// Bool m = c1.Equals (c );
// Console. WriteLine ("returned value: {0}", m );
For (int n = 0; n <c. Length; ++ n)
{
If (c1 [n]! = C [n])
{
Foreach (char var in c)
{
Console. Write (var); // read the elements in the string in sequence
 
}
Console. Out. WriteLine ("is not the number of replies. ");
Break;
}
If (n = c. Length-1)
{
Foreach (char var in c)
{
Console. Write (var );

}
Console. Out. WriteLine ("is the number of input files. ");
}
}


Console. ReadKey ();
}
}
}
</Span>

Running result:
 

 

 
 
Problem:
1. I use the c1.Equals (c) function. no matter whether the strings c1 and c are equal or not, the return value is False. If you have any idea, I will send this question to the Forum, you can also post to me on the Forum. Thank you.
The link to this issue is as follows:
 
[Csharp]
// Bool m = c1.Equals (c );
// Console. WriteLine ("returned value: {0}", m );
The following two lines of code are commented out in the source program. You can uncomment them and run them to see if they are the same as what I said.
Experience Accumulation:
1. I learned how to use the foreach statement,
 
[Csharp]
Foreach (char var in c)
{
Console. Write (var); // read the elements in the string in sequence
 
}

Execute in c first, and execute char var.
 

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.