C#初学者,不知道程序出现的BUG怎么改?请各位大神帮忙解决一下

static void Main(string[] args)
{
Console.WriteLine("请输入要判断的字符串");
string s;
s = Console.ReadLine();
if(hanshu(s)==1)
{
Console.WriteLine("输入字符串是回文串!");
}
if(hanshu(s)==0)
{
Console.WriteLine("输入字符串不是回文串!");
}
return 0;
}
int hanshu(string s[])
{
int j = s.Length;
if (j % 2 == 0)
{
int i, k;
for (i = 0, k = s.Length - 1; i <= k - 1; i++, k--)
{
if (s[i] == s[k])
{
return 1;
}
else
{
return 0;

                }
            }

        }
        if (j % 2 != 0)
        {
            int k = j / 2;
            int i;
            for (i = 1; k <= j - 1 - k; i++)
            {
                if (s[k - i] == s[k + i])
                {

                    return 1;

                }
                else
                {

                    return 0;

                }
            }
        }
}

如果你想用循环,可以这么写。

          static int hanshu(string s)
         {
             if (s == "") return 1;
             for (int i = 0; i < s.Length / 2; i++)
             {
                 if (s[i] != s[s.Length - i - 1]) return 0;
             }
             return 1;
         }  

另外,和C语言不同,C#支持bool类型,所以更地道的写法是直接用bool作为函数的返回值。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入要判断的字符串");
            string s;
            s = Console.ReadLine();
            if(hanshu(s)==1)
            {
                Console.WriteLine("输入字符串是回文串!");
            }
            if(hanshu(s)==0)
            {
                Console.WriteLine("输入字符串不是回文串!");
            }
        }
         static int hanshu(string s)
         {
             if (string.Concat(s.Reverse()) == s) return 1; else return 0;
         }  

    }
}

你一些基本的写法没掌握,比如说main是static的,你要直接调用hanshu,那么它也必须是static的,还有string s后面不需要方括号。和C++不同,C#的数组,方括号是加在类型上的。