Click here to Skip to main content
15,175,716 members
Home / Discussions / C#
   

C#

 
GeneralRe: Issue with Serial Port class Pin
Member 1206160010-Feb-16 2:18
MemberMember 1206160010-Feb-16 2:18 
GeneralRe: Issue with Serial Port class Pin
Richard MacCutchan10-Feb-16 2:30
mveRichard MacCutchan10-Feb-16 2:30 
GeneralRe: Issue with Serial Port class Pin
Member 1206160010-Feb-16 2:52
MemberMember 1206160010-Feb-16 2:52 
GeneralRe: Issue with Serial Port class Pin
Eddy Vluggen10-Feb-16 4:00
professionalEddy Vluggen10-Feb-16 4:00 
AnswerRe: Issue with Serial Port class Pin
Gerry Schmitz10-Feb-16 6:39
mveGerry Schmitz10-Feb-16 6:39 
QuestionWeb Services - Error in deserializing body of request message for operation Pin
FabeCode9-Feb-16 19:54
MemberFabeCode9-Feb-16 19:54 
AnswerRe: Web Services - Error in deserializing body of request message for operation Pin
Gerry Schmitz10-Feb-16 6:13
mveGerry Schmitz10-Feb-16 6:13 
Question'ctor design and extra "cost" of using nullable ValueTypes ? Pin
BillWoodruff9-Feb-16 1:31
mveBillWoodruff9-Feb-16 1:31 
Context: recently I have been reviewing my understanding of different options for creating constructors for .NET classes by method-overloading, and using named, and optional, parameters.

My "habit," now, is to use multiple constructors (method-overloading), and use the 'ctor modifiers 'base, and 'this as necessary.

But, consider I define a lame POCO like this:
C#
public class SomeClass
{
    public int? SomeInt1 { private set; get; }
    public int? SomeInt2 { private set; get; }
    public string SomeString { private set; get; }

    public SomeClass(int? someint1 = null, int? someint2 = null, string somestring = null)
    {
        SomeInt1 = someint1;
        SomeInt2 = someint2;
        SomeString = somestring;
    }
}
Using named parameters give me a lot of flexibility in constructing instances:
SomeClass sc1 = new SomeClass();
SomeClass sc2 = new SomeClass(someint1: 100);
SomeClass sc3 = new SomeClass(somestring: "hello");
SomeClass sc4 = new SomeClass(someint1: 999, someint2: 345, somestring: "goodbye");
SomeClass sc5 = new SomeClass(somestring: "hello", someint2: 555);
In theory the use of nullable Int32 here means I can assume ... for a given instance of the Class ... that if one of the 'ints is null, it is not initialized. Curious what you think of using nullable ValueTypes in this way in 'ctors.

I think it's a useful feature of named parameters that in VS IntelliSense will show you the names as you type a 'ctor invocation, and I like the "constraint" that named parametrs can only appear after all positional parameters, and that this:

SomeClass sc6 = new SomeClass("hello and goodbye", someint1: 999, someint2: 345);

Produces an "argument mismatch" compile-time error.

But, using 'named arguments does increase the typing you'll do, and optional parameters, possibly, ... I think you could argue ... "weakens" the strong-typing nature of your code.

Curious what your thoughts are on 'ctor writing best practice.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”


modified 9-Feb-16 9:16am.

AnswerRe: 'ctor design and extra "cost" of using nullable ValueTypes ? Pin
Pete O'Hanlon9-Feb-16 2:02
mvaPete O'Hanlon9-Feb-16 2:02 
GeneralRe: 'ctor design and extra "cost" of using nullable ValueTypes ? Pin
BillWoodruff9-Feb-16 21:08
mveBillWoodruff9-Feb-16 21:08 
GeneralRe: 'ctor design and extra "cost" of using nullable ValueTypes ? Pin
Pete O'Hanlon9-Feb-16 22:30
mvaPete O'Hanlon9-Feb-16 22:30 
SuggestionRe: 'ctor design and extra "cost" of using nullable ValueTypes ? Pin
Richard Deeming9-Feb-16 2:51
mveRichard Deeming9-Feb-16 2:51 
GeneralRe: 'ctor design and extra "cost" of using nullable ValueTypes ? Pin
BillWoodruff9-Feb-16 21:09
mveBillWoodruff9-Feb-16 21:09 
QuestionLarge terrain problem in main first game Pin
Member 122480289-Feb-16 1:25
MemberMember 122480289-Feb-16 1:25 
AnswerRe: Large terrain problem in main first game Pin
OriginalGriff9-Feb-16 1:45
mveOriginalGriff9-Feb-16 1:45 
GeneralRe: Large terrain problem in main first game Pin
Member 122480289-Feb-16 2:03
MemberMember 122480289-Feb-16 2:03 
QuestionCode or .NET class in C# similar to what inf2cat does ? Pin
Coding4DMasses9-Feb-16 0:07
MemberCoding4DMasses9-Feb-16 0:07 
AnswerRe: Code or .NET class in C# similar to what inf2cat does ? Pin
Garth J Lancaster9-Feb-16 0:45
professionalGarth J Lancaster9-Feb-16 0:45 
GeneralRe: Code or .NET class in C# similar to what inf2cat does ? Pin
Coding4DMasses9-Feb-16 0:50
MemberCoding4DMasses9-Feb-16 0:50 
Question(c#) Detection of encoding imported txt files ? Pin
Member 104109728-Feb-16 22:17
MemberMember 104109728-Feb-16 22:17 
AnswerRe: (c#) Detection of encoding imported txt files ? Pin
Thomas Daniels8-Feb-16 22:34
mentorThomas Daniels8-Feb-16 22:34 
GeneralRe: (c#) Detection of encoding imported txt files ? Pin
Member 104109729-Feb-16 0:31
MemberMember 104109729-Feb-16 0:31 
AnswerRe: (c#) Detection of encoding imported txt files ? Pin
Sascha Lefèvre8-Feb-16 22:54
professionalSascha Lefèvre8-Feb-16 22:54 
QuestionHow can i use instead of Sleep() method? Pin
sugarpasa8-Feb-16 11:11
Membersugarpasa8-Feb-16 11:11 
AnswerRe: How can i use instead of Sleep() method? Pin
Richard Andrew x648-Feb-16 12:24
professionalRichard Andrew x648-Feb-16 12:24 

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.