Amos
Amos
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
👍
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
yep
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
If you were doing this outside of string interp, you'd need to use the .ToString("FORMAT_HERE") method
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
This works using string interpolation
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
Console.WriteLine($"Start Date: {hurricane.StartDate:yyyy-MM-dd}");
Console.WriteLine($"End Date: {hurricane.EndDate:yyyy-MM-dd}\n");
Console.WriteLine($"Start Date: {hurricane.StartDate:yyyy-MM-dd}");
Console.WriteLine($"End Date: {hurricane.EndDate:yyyy-MM-dd}\n");
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
Console.WriteLine($"End Date: {hurricane.EndDate.ToString("yyyy-MM-dd"}\n")
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
You can use the to string function
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
Not saying your code is wrong. It worked. I'm just providing pointers 🙂
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
You're just passing the parameters through via constructor. Personally, I'd take this approach instead...
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; }
}
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; }
}
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
Not sure the question. I just did 1:1 to your original post
59 replies
CC#
Created by SWEETPONY on 1/26/2023 in #help
❔ What should web api controller return?
On the reading end you'd do like var movies = await httpClient.GetFromJsonAsync<List<Movie>>(URI);
14 replies
CC#
Created by SWEETPONY on 1/26/2023 in #help
❔ What should web api controller return?
It'll serialise it automatically
14 replies
CC#
Created by Boggo on 1/25/2023 in #help
❔ Image.FromStream
which parameter?
15 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
this keyword used here is unnecessary also and personally I think is ugly 😄
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
The setters aren't used in your example so the set constraint I think is unnecessary. For validation of constructor params, you could probably do all that in the constructor. Though, it'll probably get messy, quickly. Not sure what typical convention here is though. For validation, I have a separate method as part of the class to validate its members.
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
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;
}
}
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;
}
}
59 replies
CC#
Created by multisportz.hq on 1/26/2023 in #help
❔ What mistake did I make?
What framework is this? The verbosity in properties is confusing me 😄
59 replies
CC#
Created by SWEETPONY on 1/26/2023 in #help
❔ What should web api controller return?
[HttpGet("movies")]
public async Task<ActionResult<List<Movie>>> GetMovies()
{
// maybe lookup in database or something
var movies = new List<Movie>
{
new Movie
{
Name = "12 Angry Men"
}
};

return Ok(movies);
}
[HttpGet("movies")]
public async Task<ActionResult<List<Movie>>> GetMovies()
{
// maybe lookup in database or something
var movies = new List<Movie>
{
new Movie
{
Name = "12 Angry Men"
}
};

return Ok(movies);
}
14 replies
CC#
Created by Turwaith on 1/25/2023 in #help
❔ Deploying a Blazor WebAssambly app.... but how??
It's a blessing
99 replies
CC#
Created by Turwaith on 1/25/2023 in #help
❔ Deploying a Blazor WebAssambly app.... but how??
I'm working on my biggest project and it's all in Blazor Hosted. Front and Back, so far very happy with no Javascript.
99 replies