/* (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.