public string Source
{
get
{
/*
if ( Source == null ){
return string . Empty;
} else {
return Source;
Refering to ?: Operator (C# Reference)
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.
Refering to ?? Operator (C# Reference)
The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
That means:
[Part 1]
return source ?? String.Empty;
[Part 2] is not applicable ...
The ternary operator RETURNS one of two values. Or, it can execute one of two statements based on its condition, but that's generally not a good idea, as it can lead to unintended side-effects.
bar ? () : baz();
In this case, the () does nothing, while baz does something. But you've only made the code less clear. I'd go for more verbose code that's clearer and easier to maintain.
Further, this makes little sense at all:
var foo = bar ? () : baz();
since () has no return type (it's void) and baz has a return type that's unknown at the point of call in this sample. If they don't agree, the compiler will complain, and loudly.
The ternary operator (?:
) is not designed for control flow, it's only designed for conditional assignment. If you need to control the flow of your program, use a control structure, such as if
/else
.