עבור לתוכן

צריך עזרה בתרגיל ב-C#

Featured Replies

פורסם

אני אמור לקלוט תאריך בפורמט dd/mm/yyyy ולהחזיר פלט של 3 int's של התאריך (יוםת שעה ושנה)

אני אמור לכתוב את התרגיל במתודה, כתבתי משהו אבל יש לי בעיות בהמשך, המתודה שלי מקבת את הסטרינג בפורמט dd/mm/yyyy, ממירה את הסטרינג ל-int ומכניסה את ה-3 int's למערך, מעכשיו הבעיות שלי מתחילות, איך אני רושם בהמשך שידפיס לי את כל ה-int's למסך ?

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


namespace T266B
{
class Program
{


//define method
static int stDate(string date)
{


int ArrayIndex = 0;
string temp = "";


//define array
string[] stArray = new string[3];
int[] NumArray = new int[3];


//seperate the date to day, month, year, convert to int and put into array
for (int i = 0; i < date.Length; i++)
{
if (date[i] != '/' & date[i] != ' ')
{
temp += date[i];
}
else if (temp != " ")
{
int Number = int.Parse(temp);
NumArray[ArrayIndex] = Number;
Number = 0;
temp = "";
ArrayIndex++;
}
}


return 0;
}


static void Main(string[] args)
{
//read date
Console.Write("Enter Date (dd/mm/yyyy): ");
string date = Console.ReadLine();
date = date + " ";


int result = stDate(date);








}
}
}

פורסם

int[] convertDate()
{
random code;
...
int[] temp = new int[3];
temp[0] = Convert.ToInt32(ddstr);
temp[1] = Convert.ToInt32(mmstr);
temp[2] = Convert.ToInt32(yystr);
return temp;
}

וכדי להדפיס אח"כ פשוט רוץ עם לולאה על המערך המוחזר ותדפיס כל ערך.

מה גם שאני לא רואה איפה אתה מחזיר אצלך משהו חוץ מאפס..

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים