help
Root Question Message
name = this.name;
basin = this.basin;
year = this.year;
maximumspeed = this.maximumspeed;
maximumcategory = this.maximumcategory;
startdate = this.startdate;
enddate = this.enddate;
this.name = name
namespace HurricaneObject;
public static class Program
{
private static void Main()
{
var hurricanes = new List<Hurricane>
{
new("Katrina", "Atlantic", 2005, 174, 5, new DateTime(2005, 08, 23), new DateTime(2005, 08, 31)),
new("Ian", "Atlantic", 2022, 155, 5, new DateTime(2022, 09, 23), new DateTime(2022, 10, 02))
};
foreach (var hurricane in hurricanes)
{
Console.WriteLine($"Name: {hurricane.Name}");
Console.WriteLine($"Basin: {hurricane.Basin}");
Console.WriteLine($"Year: {hurricane.Year}");
Console.WriteLine($"Maximum Speed: {hurricane.MaximumSpeed}");
Console.WriteLine($"Maximum Category: {hurricane.MaximumCategory}");
Console.WriteLine($"Start Date: {hurricane.StartDate}");
Console.WriteLine($"End Date: {hurricane.EndDate}\n");
}
Console.ReadKey();
}
}
internal class Hurricane
{
public string Name { get; }
public string Basin { get; }
public int Year { get; }
public int MaximumSpeed { get; }
public int MaximumCategory { get; }
public DateTime StartDate { get; }
public DateTime EndDate { get; }
public Hurricane(string name, string basin, int year, int maximumSpeed, int maximumCategory, DateTime startDate, DateTime endDate)
{
Name = name;
Basin = basin;
Year = year;
MaximumSpeed = maximumSpeed;
MaximumCategory = maximumCategory;
StartDate = startDate;
EndDate = endDate;
}
}
this
keyword used here is unnecessary also and personally I think is ugly 😄namespace HurricaneObject;
public static class Program
{
private static void Main()
{
var hurricanes = new List<Hurricane>
{
new()
{
Name = "Katrina",
Basin = "Atlantic",
Year = 2005,
MaximumSpeed = 174,
MaximumCategory = 5,
StartDate = new DateTime(2005, 08, 23),
EndDate = new DateTime(2005, 08, 31)
},
new()
{
Name = "Ian",
Basin = "Atlantic",
Year = 2022,
MaximumSpeed = 155,
MaximumCategory = 5,
StartDate = new DateTime(2022, 09, 23),
EndDate = new DateTime(2022, 10, 02)
}
};
foreach (var hurricane in hurricanes)
{
Console.WriteLine($"Name: {hurricane.Name}");
Console.WriteLine($"Basin: {hurricane.Basin}");
Console.WriteLine($"Year: {hurricane.Year}");
Console.WriteLine($"Maximum Speed: {hurricane.MaximumSpeed}");
Console.WriteLine($"Maximum Category: {hurricane.MaximumCategory}");
Console.WriteLine($"Start Date: {hurricane.StartDate}");
Console.WriteLine($"End Date: {hurricane.EndDate}\n");
}
Console.ReadKey();
}
}
public class Hurricane
{
public string Name { get; init; } = null!;
public string Basin { get; init; } = null!;
public int Year { get; init; }
public int MaximumSpeed { get; init; }
public int MaximumCategory { get; init; }
public DateTime StartDate { get; init; }
public DateTime EndDate { get; init; }
}
Console.WriteLine($"End Date: {hurricane.EndDate.ToString("yyyy-MM-dd"}\n")
Console.WriteLine($"Start Date: {hurricane.StartDate:yyyy-MM-dd}");
Console.WriteLine($"End Date: {hurricane.EndDate:yyyy-MM-dd}\n");
.ToString("FORMAT_HERE")
method