Click here to Skip to main content
15,911,789 members
Home / Discussions / C#
   

C#

 
QuestionWhats iS THE Problem Of MY code in Monitor class For Resolve of Race Condition Pin
shahramkeyboard22-May-10 11:26
shahramkeyboard22-May-10 11:26 
AnswerRe: Whats iS THE Problem Of MY code in Monitor class For Resolve of Race Condition Pin
Luc Pattyn22-May-10 11:49
sitebuilderLuc Pattyn22-May-10 11:49 
Questionuse of ? and : [Solved] Pin
William Winner22-May-10 11:22
William Winner22-May-10 11:22 
AnswerRe: use of ? and : Pin
Pete O'Hanlon22-May-10 11:27
mvePete O'Hanlon22-May-10 11:27 
GeneralRe: use of ? and : Pin
William Winner22-May-10 11:30
William Winner22-May-10 11:30 
GeneralRe: use of ? and : Pin
Pete O'Hanlon22-May-10 11:33
mvePete O'Hanlon22-May-10 11:33 
GeneralRe: use of ? and : Pin
#realJSOP23-May-10 2:00
professional#realJSOP23-May-10 2:00 
AnswerRe: use of ? and : [Solved] Pin
DaveyM6923-May-10 1:20
professionalDaveyM6923-May-10 1:20 
Hi,

You already have your answer so I won't expand on that but I thought this may be worth mentioning.

I don't often use them because of readability issues they create. They are very useful however where it is not possible to use an if/else block such as when constructor chaining. For example, these are the constructors for an ImapClient class that I'm working on - the 3rd constructor needs to assign a port depending on the value of another parameter. I could put an if/else block inside the constructor itself but then I lose the benifit of only having code in one place that all other constructors call into. Using ?: solves this.
C#
public const int DefaultPort = 143;
public const int DefaultPortSsl = 993;
public static readonly ImapSecurity DefaultSecurity = ImapSecurity.Tls;

private string hostname;
private int port;
private ImapSecurity security;

public ImapClient(string hostname)
    : this(hostname, DefaultPort, DefaultSecurity)
{ }
public ImapClient(string hostname, int port)
    : this(hostname, port, DefaultSecurity)
{ }
public ImapClient(string hostname, ImapSecurity security)
    : this(hostname, security == ImapSecurity.Ssl ? DefaultPortSsl : DefaultPort, security)
{ }
public ImapClient(string hostname, int port, ImapSecurity security)
{
    this.hostname = hostname;
    this.port = port;
    this.security = security;
}

C#
public enum ImapSecurity
{
    None,
    Tls,
    Ssl,
}

Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

Questionhelp to translate label from dll on C# Pin
kozzzak22-May-10 11:14
kozzzak22-May-10 11:14 
AnswerRe: help to translate label from dll on C# [modified] Pin
Luc Pattyn22-May-10 11:43
sitebuilderLuc Pattyn22-May-10 11:43 
QuestionPeterson Algoritm For many Process Pin
shahramkeyboard22-May-10 10:34
shahramkeyboard22-May-10 10:34 
AnswerRe: Peterson Algoritm For many Process Pin
Pete O'Hanlon22-May-10 10:45
mvePete O'Hanlon22-May-10 10:45 
GeneralRe: Peterson Algoritm For many Process Pin
shahramkeyboard22-May-10 11:27
shahramkeyboard22-May-10 11:27 
GeneralRe: Peterson Algoritm For many Process Pin
Pete O'Hanlon22-May-10 11:33
mvePete O'Hanlon22-May-10 11:33 
QuestionSimulation Of TSL instruction For Resolve of Race Condition Pin
shahramkeyboard22-May-10 10:25
shahramkeyboard22-May-10 10:25 
AnswerRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
Pete O'Hanlon22-May-10 10:44
mvePete O'Hanlon22-May-10 10:44 
GeneralRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
shahramkeyboard22-May-10 11:28
shahramkeyboard22-May-10 11:28 
GeneralRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
Pete O'Hanlon22-May-10 11:38
mvePete O'Hanlon22-May-10 11:38 
QuestionCan I store List<> in a SQL DB? Pin
Etienne_12322-May-10 8:58
Etienne_12322-May-10 8:58 
AnswerRe: Can I store List in a SQL DB? Pin
PIEBALDconsult22-May-10 9:23
mvePIEBALDconsult22-May-10 9:23 
GeneralRe: Can I store List in a SQL DB? Pin
Luc Pattyn22-May-10 9:39
sitebuilderLuc Pattyn22-May-10 9:39 
GeneralRe: Can I store List in a SQL DB? Pin
Etienne_12322-May-10 13:23
Etienne_12322-May-10 13:23 
GeneralRe: Can I store List in a SQL DB? Pin
Luc Pattyn22-May-10 13:34
sitebuilderLuc Pattyn22-May-10 13:34 
GeneralRe: Can I store List in a SQL DB? Pin
Etienne_12323-May-10 5:41
Etienne_12323-May-10 5:41 
QuestionReflecting Entire DLL Pin
Eli Nurman22-May-10 8:23
Eli Nurman22-May-10 8:23 

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.