方法'Exists'没有重载需要'1'参数

Sto*_*boy 0 .net c# mono

我正在创建一个程序,它接受用户的用户名,年龄和ID,然后将它们打印到屏幕上.用户名不能包含任何符号或空格(_除外).所以,我创建了一个函数,true如果名称中包含符号,则返回该函数,false如果不符号则返回.但是我在编译期间遇到错误:No overload for method 'Exists' takes '1' arguments.完整的错误:

challenge_2.cs(23,37): error CS1501: No overload for method `Exists' takes `1' arguments
/usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
Run Code Online (Sandbox Code Playgroud)

这是代码:

using System;
using System.Collections.Generic;

public class Challenge_2
{
    static string myName;
    static string myAge;
    static string myUserID;
    public static char[] break_sentence(string str)
    {
        char[] characters = str.ToCharArray();
        return characters;
    }
    public static bool check_for_symbols(string s)
    {
        string[] _symbols_ = {"!","@","#","$","%","^","&","*","(",")"," ","-","+","=","~","`","\"","'","{","}","[","]","\\",":",";","<",">","?","/",","};
        List<string> symbols = new List<string>(_symbols_);
        char[] broken_s = break_sentence(s);
        int _bool_ = 0;
        for(int i = 0; i < symbols.Count; i++)
        {
            string current_symbol = symbols[i];
            if(broken_s.Exists(current_symbol))
            {
                _bool_ = 1;
                break;
            }
        }
        if(_bool_ == 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public static void Main()
    {
        Console.WriteLine("Please answer all questions wisely.");
        Console.WriteLine(" ");
        name();
        Console.WriteLine(" ");
        age();
        Console.WriteLine(" ");
        userID();
        Console.WriteLine(" ");
        string nextAge = Convert.ToString(Convert.ToInt32(myAge)+1);
        string nextID = Convert.ToString(Convert.ToInt32(myUserID)+1);
        Console.WriteLine("You are {0}, aged {1} next year you will be {2}, with user id {3}, the next user is {4}.", myName, myAge, nextAge, myUserID, nextID);
    }
    public static void name()
    {
        Console.WriteLine("What is your forum name?");
        Console.Write(">> ");
        myName = Console.ReadLine();
        while(check_for_symbols(myName) == true)
        {
            Console.WriteLine("Name can't contain symbols/spaces.");
            Console.Write("Please enter a valid forum name: ");
            myName = Console.ReadLine();
        }
    }
    public static void age()
    {
        Console.WriteLine("What is your age?");
        Console.Write(">> ");
        myAge = Console.ReadLine();
        while(Convert.ToInt32(myAge) <= 0 || Convert.ToInt32(myAge) > 120)
        {
            Console.WriteLine("That isn't a valid age.");
            Console.Write("Please enter a valid age: ");
            myAge = Console.ReadLine();
        }
    }
    public static void userID()
    {
        Console.WriteLine("What is your User ID?");
        Console.Write(">> ");
        myUserID = Console.ReadLine();
        while(Convert.ToInt32(myUserID) <= 0 || Convert.ToInt32(myUserID) > 999999)
        {
            Console.WriteLine("UserID must be in the range: 0 < x < 1000000.");
            Console.Write("Please enter a valid user ID: ");
            myUserID = Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

Kar*_*son 5

替换你的这部分功能

        string current_symbol = symbols[i];
        if(broken_s.Exists(current_symbol))
        {
            _bool_ = 1;
            break;
        }
Run Code Online (Sandbox Code Playgroud)

        string current_symbol = symbols[i];
        if(broken_s.Contains(current_symbol))
        {
            _bool_ = 1;
            break;
        }
Run Code Online (Sandbox Code Playgroud)

干杯!