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

C#

 
AnswerRe: C# versus C++, null references and protecting against them Pin
Pete O'Hanlon14-Jan-11 9:14
mvePete O'Hanlon14-Jan-11 9:14 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 9:58
bob1697214-Jan-11 9:58 
GeneralRe: C# versus C++, null references and protecting against them Pin
Pete O'Hanlon14-Jan-11 10:55
mvePete O'Hanlon14-Jan-11 10:55 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 10:48
bob1697214-Jan-11 10:48 
AnswerRe: C# versus C++, null references and protecting against them Pin
jschell14-Jan-11 9:46
jschell14-Jan-11 9:46 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697214-Jan-11 10:23
bob1697214-Jan-11 10:23 
GeneralRe: C# versus C++, null references and protecting against them Pin
jschell15-Jan-11 9:44
jschell15-Jan-11 9:44 
AnswerRe: C# versus C++, null references and protecting against them Pin
Paul Michalik15-Jan-11 2:23
Paul Michalik15-Jan-11 2:23 
bob16972 wrote:
Someone please tell me there is a way to eliminate all these checks for null references in C# like I could in C++.


Hm, there is nothing like "null reference" in a C++ program. This would require dereferencing a null-pointer which immediately results in undefined behaviour of the rest of the program. If you pass an object by reference in C++, you implicitly state that this object cannot be a reference to null object by definition.

In managed code you can use explicit code contracts. CCs allow you to make explicit assumptions about pre-, post- or state-conditions which are verifiable at compile- and run-time. You formulate contracts at metadata level so they get injected into IL in AOP manner:

[ContractClass(typeof(ISomethingContract))]
public interface ISomething {
    public void DoSomething(AnotherClass pObject);
}

[ContractClassFor(typeof(ISomething))]
internal abstract class SomethingContract : ISomething {
    public void DoSomething(AnotherClass pObject) {
        Contract.Requires(pObject != null);
    }
}
}

AnswerRe: C# versus C++, null references and protecting against them Pin
PIEBALDconsult15-Jan-11 4:12
mvePIEBALDconsult15-Jan-11 4:12 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697215-Jan-11 5:00
bob1697215-Jan-11 5:00 
AnswerRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole15-Jan-11 17:14
Chuck O'Toole15-Jan-11 17:14 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697215-Jan-11 19:23
bob1697215-Jan-11 19:23 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole15-Jan-11 20:56
Chuck O'Toole15-Jan-11 20:56 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 5:24
bob1697216-Jan-11 5:24 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 6:00
Chuck O'Toole16-Jan-11 6:00 
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik16-Jan-11 7:39
Paul Michalik16-Jan-11 7:39 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 7:57
Chuck O'Toole16-Jan-11 7:57 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 8:30
Chuck O'Toole16-Jan-11 8:30 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 12:29
bob1697216-Jan-11 12:29 
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik16-Jan-11 20:35
Paul Michalik16-Jan-11 20:35 
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik15-Jan-11 23:04
Paul Michalik15-Jan-11 23:04 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 4:57
bob1697216-Jan-11 4:57 
QuestionCOM error [modified] Pin
polycom12314-Jan-11 8:05
polycom12314-Jan-11 8:05 
QuestionDynamic assembly information Pin
Helfdane14-Jan-11 2:32
Helfdane14-Jan-11 2:32 
AnswerRe: Dynamic assembly information Pin
Ravi Sant14-Jan-11 3:49
Ravi Sant14-Jan-11 3:49 

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.