Make sure to delete the comments tag " //,/./ "
/*
Part One: Creating A Class:
- THIS IS HOW YOU CREATE A CLASS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //business Rules
- namespace DataApp
- {
class Date
{
// list data members
private int month;
private int day;
private int year;
private string monthName;
// Default constructor
public Date()
{
}
// Other Constructors
public Date(int m, int d, int y)
{
month = m;
day = d;
year = y;
}
public Date(string mon, int d, int y)
{
monthName = mon;
day = d;
year = y;
}
// followed by Special methods getter and setter (PROPERTY)
public int Month
{
get
{
return month
}
set
{
month = value;
}
}
public int Day
{
get
{
return day
}
set
{
day = value;
}
}
public int Year
{
get
{
return year
}
set
{
year = value;
}
}
public string MonthName
{
get
{
return monthName
}
set
{
monthName = value;
}
}
public string ReturnLongDate() //Displaying result
{
return monthName + " " + day + " " + year;
}
public override string ToString()
{
return month + "/" + day + "/" + year;
}
}
- }
Part Two: Applying the Class
- This is How You Apply it to the MAIN function.
- using System;
- using static System.Console;
- namespace DataApp
- {
class DataApp
{
static void Main(string[] args)
{
// Creating an object of the class name version
Date aDate = new Date();
aDate.Month = AskForInput("Month");
aDate.Day = AskForInput("Day");
aDate.Year = AskForInput("Year");
WriteLine("\n\tFirst Test");
WriteLine(aDate);
// Create an object of the class version 2
Date secondDate = new Date();
secondDate.Month = 3;
secondDate.Day = 20;
secondDate.Year = 2017;
WriteLine("\n\tSecond Test");
WriteLine(secondDate);
// create an object of the class data version 3
WriteLine("\n\tThird Test");
Date anotherDate = new Date(2, 2, 2017);
WriteLine("Date: " + anotherDate.ToString());
//Create an object of the class data version 4
WriteLine("\n\t4h Test");
Date lastOne = new Date("October", 6, 2019);
WriteLine(lastOne.ReturnLongDate());
ReadKey();
//41.
//42. }
//43.
//44. // user input
//45. static int AskForInput(string WhichOne)
//46. {
//47. string inValue;
//48. WriteLine("Enter a number representing the {0}", WhichOne);
//49. inValue = ReadLine();
//50. return (int.Parse(inValue));
//51.
//52. }
//53. }
//54. }
Thats How You Create A Simple Class With C#