TahaA
TahaA
CC#
Created by TahaA on 6/24/2024 in #help
✅ where constraint on interface method
Is it even possible? Like public void RefuelCar<c>(c Car) where c : IUseGas.Refuel Here the generic type is constrainted to where it implements an interface's method, whereas the name of the interface is IUseGas
22 replies
CC#
Created by TahaA on 5/20/2024 in #help
Is implementing ICloneable in unittests worthless?
ICloneable of course we use to clone reference type variables since they point to the same memory address which implies that any changes to the original reference (like string1) will also change all copies (like string2) that aren't cloned with ICloneable. Now I haven't used ICloneable in unittests before, but it seems that it doesn't work. Perhaps it is because there's a conflict with other interfaces, or packages in the csproj, all that stuff that on my level (1st year student without foreknowledge) I wouldn't know about, so that's why I'm asking, what are your experiences? Is my hypothesis of internal conflicts possible, or is ICloneable really just worthless on unittests?
2 replies
CC#
Created by TahaA on 5/15/2024 in #help
Comments in curried lambda expression
Just a quick question. Do you think the comments I used here are correct? If needed I'll provide the whole code:
public static Func<double, Func<double, double>> GetPriceCalculator(double taxRate)
{
Func<double /*discount*/, Func<double /*price*/, double/*final price*/>> GetFinalPrice = discount => price => price * (1 - discount) * (1 + taxRate);
return GetFinalPrice;
}
public static Func<double, Func<double, double>> GetPriceCalculator(double taxRate)
{
Func<double /*discount*/, Func<double /*price*/, double/*final price*/>> GetFinalPrice = discount => price => price * (1 - discount) * (1 + taxRate);
return GetFinalPrice;
}
8 replies
CC#
Created by TahaA on 5/12/2024 in #help
Can't retrieve data because of JsonIgnore
I'm using JsonIgnore to not include the data in the JSON file (the two properties where I'm using [JsonIgnore] are not allowed to be put inside the JSON file). The problem is that no matter what I've tried until now to retrieve the data in the overriden ToString() method, the datamodel that should contain the TimeTitlePair is always empty/null. I have never had C# up until this semester and this is one of the places where I struggle. I'll show the full code below:
5 replies