Click here to Skip to main content
15,909,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: Excel's MOD in C#? Pin
Jassim Rahma18-Aug-19 22:18
Jassim Rahma18-Aug-19 22:18 
GeneralRe: Excel's MOD in C#? Pin
Peter_in_278018-Aug-19 22:25
professionalPeter_in_278018-Aug-19 22:25 
AnswerRe: Excel's MOD in C#? Pin
OriginalGriff18-Aug-19 22:08
mveOriginalGriff18-Aug-19 22:08 
GeneralRe: Excel's MOD in C#? Pin
Jassim Rahma18-Aug-19 22:22
Jassim Rahma18-Aug-19 22:22 
GeneralRe: Excel's MOD in C#? Pin
OriginalGriff18-Aug-19 22:28
mveOriginalGriff18-Aug-19 22:28 
GeneralRe: Excel's MOD in C#? Pin
BillWoodruff19-Aug-19 21:48
professionalBillWoodruff19-Aug-19 21:48 
AnswerRe: Excel's MOD in C#? Pin
BillWoodruff19-Aug-19 23:43
professionalBillWoodruff19-Aug-19 23:43 
SuggestionRe: Excel's MOD in C#? Pin
Richard Deeming20-Aug-19 1:39
mveRichard Deeming20-Aug-19 1:39 
BillWoodruff wrote:
C#
catch (InvalidCastException iex)
{
    throw new InvalidCastException($"type {typeof(T)} cannot be cast to double: {iex.Message}");
}
If you're going to wrap an exception, you should pass the wrapped exception as the inner exception.

You should probably review the error messages as well. For example, it might be fine to use the given type, but not the specified value.
C#
catch (InvalidCastException iex)
{
    throw new InvalidCastException($"Type {typeof(T)} cannot be cast to double: {iex.Message}", iex);
}
catch (FormatException fex)
{
    throw new FormatException($"Value '{i1}' of type {typeof(T)} cannot be converted to a double: {fex.Message}", fex);
}
catch (OverflowException oex)
{
    throw new OverflowException($"Value '{i1}' of type {typeof(T)} is too large for a double: {oex.Message}", oex);
}
You can also eliminate the InvalidCastException by adding a generic type constraint, since the documentation[^] says it's only thrown if the value to convert doesn't implement IConvertible:
C#
public static double ModT<T>(this T i1, T i2) where T : IConvertible { ... }
public static double ModT1T2<T1, T2>(this T1 i1, T2 i2) where T1 : IConvertible where T2 : IConvertible { ... }
public static double GetDouble<T>(this T i1) where T : IConvertible { ... }




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Excel's MOD in C#? Pin
BillWoodruff20-Aug-19 3:07
professionalBillWoodruff20-Aug-19 3:07 
GeneralRe: Excel's MOD in C#? Pin
Richard Deeming20-Aug-19 3:23
mveRichard Deeming20-Aug-19 3:23 
GeneralRe: Excel's MOD in C#? Pin
BillWoodruff20-Aug-19 4:42
professionalBillWoodruff20-Aug-19 4:42 
GeneralRe: Excel's MOD in C#? Pin
Richard Deeming20-Aug-19 5:27
mveRichard Deeming20-Aug-19 5:27 
Questionc# Pin
Member 1456180618-Aug-19 5:22
Member 1456180618-Aug-19 5:22 
AnswerRe: c# Pin
OriginalGriff18-Aug-19 6:35
mveOriginalGriff18-Aug-19 6:35 
AnswerRe: c# Pin
#realJSOP21-Aug-19 1:38
professional#realJSOP21-Aug-19 1:38 
QuestionZKTeco merge 3 finger print C# with ZKFingerSDK Pin
Rikus Marais14-Aug-19 2:33
Rikus Marais14-Aug-19 2:33 
AnswerRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
OriginalGriff14-Aug-19 4:08
mveOriginalGriff14-Aug-19 4:08 
GeneralRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
Richard Deeming14-Aug-19 7:56
mveRichard Deeming14-Aug-19 7:56 
AnswerRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
Gerry Schmitz15-Aug-19 4:02
mveGerry Schmitz15-Aug-19 4:02 
GeneralRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
OriginalGriff15-Aug-19 4:12
mveOriginalGriff15-Aug-19 4:12 
GeneralRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
Richard Deeming15-Aug-19 4:33
mveRichard Deeming15-Aug-19 4:33 
GeneralRe: ZKTeco merge 3 finger print C# with ZKFingerSDK Pin
Gerry Schmitz15-Aug-19 9:26
mveGerry Schmitz15-Aug-19 9:26 
QuestionHow i can convert perl scripts to exe file to use in c#? Pin
Member 1455624211-Aug-19 1:25
Member 1455624211-Aug-19 1:25 
AnswerRe: How i can convert perl scripts to exe file to use in c#? Pin
OriginalGriff11-Aug-19 1:28
mveOriginalGriff11-Aug-19 1:28 
AnswerRe: How i can convert perl scripts to exe file to use in c#? Pin
Richard MacCutchan11-Aug-19 3:32
mveRichard MacCutchan11-Aug-19 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.