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

C#

 
AnswerRe: SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7 Pin
Dave Kreskowiak2-Sep-16 9:17
mveDave Kreskowiak2-Sep-16 9:17 
GeneralRe: SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7 Pin
Tej_dev6-Sep-16 6:47
Tej_dev6-Sep-16 6:47 
GeneralRe: SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7 Pin
Dave Kreskowiak6-Sep-16 9:31
mveDave Kreskowiak6-Sep-16 9:31 
QuestionWhat kind of relation is created with virtual keyword in EF Pin
Tridip Bhattacharjee2-Sep-16 2:46
professionalTridip Bhattacharjee2-Sep-16 2:46 
AnswerRe: What kind of relation is created with virtual keyword in EF Pin
Pete O'Hanlon2-Sep-16 3:10
mvePete O'Hanlon2-Sep-16 3:10 
QuestionOverride properties in derived classes - some have fixed value, some do not Pin
amaturi1-Sep-16 22:32
amaturi1-Sep-16 22:32 
AnswerRe: Override properties in derived classes - some have fixed value, some do not Pin
Pete O'Hanlon1-Sep-16 22:57
mvePete O'Hanlon1-Sep-16 22:57 
AnswerRe: Override properties in derived classes - some have fixed value, some do not PinPopular
OriginalGriff1-Sep-16 23:13
mveOriginalGriff1-Sep-16 23:13 
As Pete says, you don't have to put anything in the setter.
But I must admit, I don't like that, as you can still write:
C#
DerivedClass dc = new DerivedClass();
dc.SomeProperty = 23.0;

And it will appear to work - there is no compile or runtime error here which is potentially confusing:
C#
public class DerivedClass2 : BaseClass
    {
    public override double SomeProperty { get; set; }
    }

Allows:
C#
BaseClass bc = new DerivedClass();
bc.SomeProperty = 23.0;
bc = new DerivedClass2();
bc.SomeProperty = 23.0;

Which doesn't do the same thing in both cases.
You could throw an exception in the "unwanted" setter:
C#
public class DerivedClass : BaseClass
    {
    public override double SomeProperty
        {
        get { return 1d; }
        set { throw new ApplicationException("Cannot set SomeProperty of DerivedClass - it is read only");  }
        }
    }

But that just moves the problem to runtime and I don't like that either.
It might be better to make the Setter protected:
C#
public abstract class BaseClass
    {
    public abstract double SomeProperty { get; protected set; }
    }

Because at least then you are restricting the confusion to classes that are directly involved, instead of letting the rest of the world get confused as well.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: Override properties in derived classes - some have fixed value, some do not Pin
BillWoodruff2-Sep-16 1:49
professionalBillWoodruff2-Sep-16 1:49 
GeneralRe: Override properties in derived classes - some have fixed value, some do not Pin
OriginalGriff2-Sep-16 3:57
mveOriginalGriff2-Sep-16 3:57 
QuestionTimeStamp to PDF Pin
Member 119141971-Sep-16 22:06
Member 119141971-Sep-16 22:06 
QuestionSuggesstions on saving 100s of rowsto the database Pin
Giridhar Aruri1-Sep-16 15:27
Giridhar Aruri1-Sep-16 15:27 
AnswerRe: Suggesstions on saving 100s of rowsto the database Pin
OriginalGriff1-Sep-16 20:22
mveOriginalGriff1-Sep-16 20:22 
AnswerRe: Suggesstions on saving 100s of rowsto the database Pin
Eddy Vluggen1-Sep-16 23:10
professionalEddy Vluggen1-Sep-16 23:10 
QuestionNeed to cancel BackgroundWorker Pin
David_411-Sep-16 13:01
David_411-Sep-16 13:01 
AnswerRe: Need to cancel BackgroundWorker Pin
Pete O'Hanlon1-Sep-16 21:01
mvePete O'Hanlon1-Sep-16 21:01 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 8:12
David_416-Sep-16 8:12 
GeneralRe: Need to cancel BackgroundWorker Pin
Pete O'Hanlon6-Sep-16 9:39
mvePete O'Hanlon6-Sep-16 9:39 
AnswerRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz3-Sep-16 6:53
mveGerry Schmitz3-Sep-16 6:53 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 8:20
David_416-Sep-16 8:20 
GeneralRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz6-Sep-16 9:08
mveGerry Schmitz6-Sep-16 9:08 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 9:14
David_416-Sep-16 9:14 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 9:18
David_416-Sep-16 9:18 
GeneralRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz6-Sep-16 9:48
mveGerry Schmitz6-Sep-16 9:48 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 10:05
David_416-Sep-16 10:05 

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.