Please tell me what's wrong with my code :V

Khoa

New member
Joined
Oct 29, 2021
Messages
1
Programming Experience
Beginner
C#:
using System;
namespace String {
    class Program {
        static void Main(string[] args) {
            string s = Console.ReadLine();
            int a = s.Length;
            for ( int i =0; i < s.Length; i+=1){
                char temp = s[I];
                s[a - 1] = s[I];
                s[I] = temp;
                a -=1;
            }
           for ( int z =0; z < s.Length; z+=1){
           Console.Write(a[z]);
}
        }
    }
}
 
Last edited by a moderator:
In the future, please post your code on code tags.

Without telling us what the code is supposed to do, or what errors you are running into, we can't really tell what is wrong with the behavior of your code.

Syntax wise:
It looks like you forgot that C# is case sensitive and so I on lines 8-10 should really be i. Or perhaps you did use i there, but when you posted your code here, but failed to put your code in code tags, the forum software made into I.

Behavior wise:
Maybe you really intended to basically have a loop that effectively does nothing in your lines 6-12. Or was your intent to reverse the string? In which case the C# string has a built-in to do that.

Maybe you really wanted to print out your string the hard way on lines 12-13 instead of just using WriteLine().

Style wise:
The indents and parenthesis look inconsistent. Perhaps stick with always using spaces, or always using tabs for indents.

It looks like you are using the Java One Brace Style of braces and indents. C# indent style is Allman with the opening brace on the next line.

Using an identifier name that matches a well known system type is usually a bad idea and can cause confusion for experienced programmers. Choose a better namespace name than String .
 
Last edited:
Back
Top Bottom