can you guys tell me why this program don't change my input string into lower case string containing only letters? I mean only letter part does work but letters don't change to lower case. When I write YELLOW, I should see yellow in the window but I still ses YELLOW all upper case as the output.
namespace ConsoleApplication6
{
class czlowiek
{
private string _imie;
private string _nazwisko;
private int _wiek;
public string imie
{
get
{
return _imie;
}
set
{
for (int i = 0; i < value.Length; i++)
{
if (Convert.ToInt32(char.ToLower(value[i])) >= 97 && Convert.ToInt32(char.ToLower(value[i])) <= 122)
_imie += value[i];
}
}
}
public string nazwisko
{
get
{
return _nazwisko;
}
set
{
for (int i = 0; i < value.Length; i++)
{
if (Convert.ToInt32(char.ToLower(value[i])) >= 97 && Convert.ToInt32(char.ToLower(value[i])) <= 122)
_nazwisko += value[i];
}
}
}
public int wiek
{
get
{
if (_wiek < 0 || _wiek > 100)
return 0;
else
return _wiek;
}
set
{
if (value < 0 || value > 100)
Console.WriteLine("Wporwadzona wartość niepoprawna");
else
_wiek = value;
}
}
}
}
and main program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
czlowiek admin = new czlowiek();
Console.Write("Podaj swoje imie: ");
admin.imie = Console.ReadLine();
Console.WriteLine("Cześć {0}!", admin.imie);
Console.WriteLine("Podaj swój wiek: ");
admin.wiek = int.Parse(Console.ReadLine());
if (admin.wiek != 0)
Console.Write("Masz {0}", admin.wiek);
Console.ReadLine();
}
}
}
You should set values like this:
_imie += char.ToLower(value[i]);
_nazwisko += char.ToLower(value[i]);