Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
QuestionPlay/Pause/Stop media through ASIO driver using C# Pin
Praveen Raghuvanshi16-Oct-14 18:16
professionalPraveen Raghuvanshi16-Oct-14 18:16 
AnswerRe: Play/Pause/Stop media through ASIO driver using C# Pin
Brisingr Aerowing17-Oct-14 10:08
professionalBrisingr Aerowing17-Oct-14 10:08 
GeneralRe: Play/Pause/Stop media through ASIO driver using C# Pin
Praveen Raghuvanshi26-Oct-14 7:37
professionalPraveen Raghuvanshi26-Oct-14 7:37 
Questionanother Func-enstein weirdness : and yet another bad example of MS documentation PinPopular
BillWoodruff16-Oct-14 11:38
professionalBillWoodruff16-Oct-14 11:38 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
Gerry Schmitz16-Oct-14 17:43
mveGerry Schmitz16-Oct-14 17:43 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
OriginalGriff16-Oct-14 19:27
mveOriginalGriff16-Oct-14 19:27 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
Richard Deeming17-Oct-14 5:28
mveRichard Deeming17-Oct-14 5:28 
Questionnecessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 7:25
professionalBillWoodruff16-Oct-14 7:25 
I have a bright student who I assigned a "challenge" of writing a calculator that uses Funcs, or Lambda expressions, and a Dictionary, to provide a central "dispatch" method for various math calculations. Said student came back puzzled by why his Dictionary definition wouldn't compile, and I could not give him a satisfactory answer as to why a cast to nullable int was required.

Perhaps it's in the nature of the compile process for a Func/Lambda inside an auto-initializing Dictionary declaration ?

The compiler has no problem with this:
C#
int? nullInt = null;

// however, in this Dictionary declaration: a cast of null to int?

private Dictionary<string, Func<int, int, int?>> dctOps = new Dictionary<string, Func<int, int, int?>>
{
    { "+", (i1, i2) => i1 + i2 },
    { "-", (i1, i2) => i1 - i2 },
    // cast to nullable required !
    { "/", (i1, i2) => ((i2 == 0) ? (int?) null : i1/i2) },
    { "*", (i1, i2) => i1 * i2 }
};
fyi, usage:
C#
private int? CalcTwoInts(string op, int i1, int i2)
{
    Func<int, int, int?> func;

    if (dctOps.TryGetValue(op, out func)) return func(i1, i2);

    throw new ArgumentException(op + " is not a legal key");
}

int? test3 = CalcTwoInts("/", 100, 0);

if(test3 == null)
{
    // handle null
}
else
{
    // okay
}

« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali

AnswerRe: necessity to cast return value to nullable in lambda expression ? Pin
Richard Deeming16-Oct-14 8:12
mveRichard Deeming16-Oct-14 8:12 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 8:44
professionalBillWoodruff16-Oct-14 8:44 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
Richard Deeming16-Oct-14 8:49
mveRichard Deeming16-Oct-14 8:49 
AnswerRe: necessity to cast return value to nullable in lambda expression ? Pin
Pete O'Hanlon16-Oct-14 8:13
mvePete O'Hanlon16-Oct-14 8:13 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 8:44
professionalBillWoodruff16-Oct-14 8:44 
QuestionHow to read tables in Excel Worksheet witc C# and XML Pin
Member 1110881716-Oct-14 3:13
Member 1110881716-Oct-14 3:13 
AnswerRe: How to read tables in Excel Worksheet witc C# and XML Pin
BillWoodruff16-Oct-14 5:25
professionalBillWoodruff16-Oct-14 5:25 
GeneralRe: How to read tables in Excel Worksheet witc C# and XML Pin
Member 1110881716-Oct-14 21:14
Member 1110881716-Oct-14 21:14 
AnswerRe: How to read tables in Excel Worksheet witc C# and XML Pin
Eddy Vluggen16-Oct-14 9:05
professionalEddy Vluggen16-Oct-14 9:05 
QuestionC#/C wrapper Pin
Nikolaj jensen16-Oct-14 2:39
Nikolaj jensen16-Oct-14 2:39 
AnswerRe: C#/C wrapper Pin
Richard MacCutchan16-Oct-14 2:59
mveRichard MacCutchan16-Oct-14 2:59 
GeneralRe: C#/C wrapper Pin
Nikolaj jensen16-Oct-14 3:52
Nikolaj jensen16-Oct-14 3:52 
GeneralRe: C#/C wrapper Pin
Richard MacCutchan16-Oct-14 3:56
mveRichard MacCutchan16-Oct-14 3:56 
GeneralRe: C#/C wrapper Pin
Nikolaj jensen16-Oct-14 21:43
Nikolaj jensen16-Oct-14 21:43 
QuestionHow to convert HTML Form data into RTF File Pin
mukulsharma114616-Oct-14 1:37
mukulsharma114616-Oct-14 1:37 
AnswerRe: How to convert HTML Form data into RTF File Pin
Richard MacCutchan16-Oct-14 2:55
mveRichard MacCutchan16-Oct-14 2:55 
AnswerRe: How to convert HTML Form data into RTF File Pin
Eddy Vluggen16-Oct-14 9:07
professionalEddy Vluggen16-Oct-14 9:07 

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.