Click here to Skip to main content
15,895,709 members
Home / Discussions / C#
   

C#

 
GeneralRe: Threading related naming and usage of const Pin
HobbyProggy21-Jun-23 3:16
professionalHobbyProggy21-Jun-23 3:16 
GeneralRe: Threading related naming and usage of const Pin
harold aptroot20-Jun-23 15:07
harold aptroot20-Jun-23 15:07 
GeneralRe: Threading related naming and usage of const Pin
HobbyProggy20-Jun-23 23:04
professionalHobbyProggy20-Jun-23 23:04 
AnswerRe: Threading related naming and usage of const Pin
Gerry Schmitz21-Jun-23 4:42
mveGerry Schmitz21-Jun-23 4:42 
AnswerRe: Threading related naming and usage of const Pin
jschell23-Jun-23 10:53
jschell23-Jun-23 10:53 
GeneralRe: Threading related naming and usage of const Pin
HobbyProggy6-Jul-23 3:55
professionalHobbyProggy6-Jul-23 3:55 
QuestionMonospaced font (i.e. "Terminal" font in FontDialog Pin
Ronald Boucher14-Jun-23 12:53
Ronald Boucher14-Jun-23 12:53 
AnswerRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
Gerry Schmitz14-Jun-23 17:34
mveGerry Schmitz14-Jun-23 17:34 
AnswerRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
jschell15-Jun-23 2:47
jschell15-Jun-23 2:47 
AnswerRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
trønderen15-Jun-23 4:15
trønderen15-Jun-23 4:15 
AnswerRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
Dave Kreskowiak15-Jun-23 7:38
mveDave Kreskowiak15-Jun-23 7:38 
GeneralRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
Richard Andrew x6415-Jun-23 14:56
professionalRichard Andrew x6415-Jun-23 14:56 
GeneralRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
jschell16-Jun-23 9:58
jschell16-Jun-23 9:58 
GeneralRe: Monospaced font (i.e. "Terminal" font in FontDialog Pin
trønderen19-Jun-23 8:48
trønderen19-Jun-23 8:48 
QuestionReferencing an Array from another Class Pin
Member 1602947114-Jun-23 5:44
Member 1602947114-Jun-23 5:44 
AnswerRe: Referencing an Array from another Class Pin
OriginalGriff14-Jun-23 6:00
mveOriginalGriff14-Jun-23 6:00 
AnswerRe: Referencing an Array from another Class Pin
jschell14-Jun-23 6:11
jschell14-Jun-23 6:11 
QuestionHow to use switch case instead of if statements? Pin
Member 1405587912-Jun-23 0:28
Member 1405587912-Jun-23 0:28 
AnswerRe: How to use switch case instead of if statements? Pin
Richard Deeming12-Jun-23 1:06
mveRichard Deeming12-Jun-23 1:06 
That depends on which language version you're using. Relational patterns[^] were added in C# 9.0:
C#
switch (number)
{
    case > 70:
    {
        ...
        break;
    }
    case > 50:
    {
        ...
        break;
    }
    case > 30:
    {
        ...
        break;
    }
    case > 20:
    {
        ...
        break;
    }
}
NB: Unlike older switch statements, the order of the cases matters. The first matching case will be applied, meaning that you need to reverse the order of your tests - 71 is greater than 20, so if case > 20 was first, that would be the case that matched.

Also note that you're using if rather than else if, so the code code > 20 will also execute for values greater than 70. There doesn't seem to be a goto case ... syntax for relational patterns, so if that's the required behaviour, you would need to duplicate the code in each case:
C#
switch (number)
{
    case > 70:
    {
        // Process > 70
        // Process > 50
        // Process > 30
        // Process > 20
        break;
    }
    case > 50:
    {
        // Process > 50
        // Process > 30
        // Process > 20
        break;
    }
    case > 30:
    {
        // Process > 30
        // Process > 20
        break;
    }
    case > 20:
    {
        // Process > 20
        break;
    }
}
This would potentially make the code messier than your current version.

And if the code in the if blocks modifies the number variable in any way, it gets even messier.



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

AnswerRe: How to use switch case instead of if statements? Pin
jschell12-Jun-23 11:09
jschell12-Jun-23 11:09 
QuestionClean code in C# development Pin
WeiminYu10-Jun-23 18:27
WeiminYu10-Jun-23 18:27 
AnswerRe: Clean code in C# development Pin
OriginalGriff10-Jun-23 18:31
mveOriginalGriff10-Jun-23 18:31 
GeneralRe: Clean code in C# development Pin
Richard Andrew x6411-Jun-23 7:17
professionalRichard Andrew x6411-Jun-23 7:17 
GeneralRe: Clean code in C# development Pin
OriginalGriff11-Jun-23 8:32
mveOriginalGriff11-Jun-23 8:32 
GeneralRe: Clean code in C# development Pin
trønderen11-Jun-23 11:20
trønderen11-Jun-23 11:20 

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.