u/PaskettiMonster1

Question on Convert.ChangeType
▲ 3 r/csharp

Question on Convert.ChangeType

From Microsoft's documentation, https://learn.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=net-10.0 it seems like "Convert.ChangeType(double number, typeof(int))" would return an int. However I see that in reality, the result has to still be explicitly cast afterwards like (int)Convert.ChangeType(double number, typeof(int))". From what I understand, Convert.ChangeType is changing a double to the base "object" class in the example above, and then that object still has to be converted (via the cast) to the int. So why does it require the conversiontype as an argument then? Confusing!

u/PaskettiMonster1 — 11 hours ago
▲ 6 r/csharp

Help with text processing based on file type

I'm learning C# by taking some Udemy courses and I'm working on refactoring some code for one of the exercises (which I'm sure is terrible, I'm a complete newbie). In this case I'd like to make this method into a more reusable "LoadFromFile". The only thing that would change is the way that the string[] ingredientNumbersAsStringsFromRecipe gets built based on the fileFormat enum that's passed to it (for a text file it would just be string.Split for example. However I can't put an "if" statement in there because if I initiatilze the string[] in the "if" block then I can't use it outside of that local scope. I would appreciate any tips on how this could be better handled! (By the way I know that in general I should use int.TryParse, in this case this program is making the same file that it reads from so int.Parse is safe.)

public static List<Recipe> LoadFromJson(string fileName, FileFormats fileFormat, List<Ingredient> availableIngredients)
{
    string[] recipeStringList = File.ReadAllLines(fileName);
    List<Recipe> recipeList = new List<Recipe>();
    foreach (string recipe in recipeStringList)
    {
        string[] ingredientNumbersAsStringsFromRecipe = JsonSerializer.Deserialize<string>(recipe).Split(',');
        List<int> ingredientNumbersAsIntsFromRecipe = new List<int>();
        foreach (string x in ingredientNumbersAsStringsFromRecipe)
        {
            ingredientNumbersAsIntsFromRecipe.Add(int.Parse(x));
        }
        Recipe loadedRecipe = new Recipe();
        foreach (int ingredient in ingredientNumbersAsIntsFromRecipe)
        {
            loadedRecipe.IngredientsInRecipe.Add(availableIngredients[availableIngredients.FindIndex(x => x.Id == ingredient)]);
        }
        recipeList.Add(loadedRecipe);
    }
    return recipeList;

}
reddit.com
u/PaskettiMonster1 — 20 days ago

USB-C hub for 3440×1440 @ 60 hz (HDMI or DP)

I tried a USB-C hub off of Amazon which supports 4K @ 60 hz via HDMI. But I couldn't get it to output at 3440 x 1440 until I dropped it to 30 hz. I guess there's some sort of down conversion it does that affects the framerate it can handle. Does anyone know of a USB-C hub that supports 3440 x 1440 at 60 hz?

reddit.com
u/PaskettiMonster1 — 1 month ago
▲ 1 r/Laptop

USB-C hub for 3440×1440 @ 60 hz (HDMI or DP)

I tried a USB-C hub off of Amazon which supports 4K @ 60 hz via HDMI. But I couldn't get it to output at 3440 x 1440 until I dropped it to 30 hz. I guess there's some sort of down conversion it does that affects the framerate it can handle. Does anyone know of a USB-C hub that supports 3440 x 1440 at 60 hz?

reddit.com
u/PaskettiMonster1 — 1 month ago