I am making a program that takes the Username, Age and ID of an user and then prints them out to the screen. The username can't contain any symbols or spaces (except _). So, I made a function that returns true
if the name has symbols in it and false
if it doesn't. However I am getting an error during compiling: No overload for method 'Exists' takes '1' arguments
.
The full error:
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
Here is the code:
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();
}
}
}
Any help is appreciated.