Zdravím, Mám problém s Dátovými typmi. Rozhodol som sa že trosku "optimalizujem" svoj program ale po zmene int na iný typ napr. byte mi to hádže chyby.
Zdroják:
Kód:
namespace pocitadlo
{
public partial class Form1 : Form
{
byte day;
byte month;
ushort year;
byte aday;
byte amonth;
ushort ayear;
ushort v;
byte age;
byte[] months = new byte[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public Form1()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
ushort s1 = 0;
ushort s2 = 0;
day = byte.Parse(txtDay.Text);
month = byte.Parse(txtMonth.Text);
year = ushort.Parse(txtYear.Text);
aday = byte.Parse(txtADay.Text);
amonth = byte.Parse(txtAMonth.Text);
ayear = ushort.Parse(txtAYear.Text);
if (year % 4 == 0 && ayear % 4 == 0)
months[2] = 29;
else months[2] = 28;
for (int i = 1; i <= month; i++)
s1 += months[i];
for (int i = 1; i <= amonth; i++)
s2 += months[i];
v = (s1 + day) - (s2 + aday);
if (day == aday && month == amonth)
{
age = ayear - year;
if (year % 4 == 0 && ayear % 4 == 0)
v = v + 366;
else v = v + 365;
}
else age = (ayear - year) - 1;
if (v < 0)
{
age++;
if (year % 4 == 0 && ayear % 4 == 0)
v = v + 366;
else v = v + 365;
}
Output1.Text = "Máš "+ age +" rokov";
Output2.Text = "Za "+ v.ToString() + " dní budeš mať narodeniny";
}
}
}
Chyby:
Kód:
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\CError CS0266 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) pocitadlo C:\Users\GamerSK\Documents\C