Click here to Skip to main content
15,120,477 members
Home / Discussions / C#
   

C#

 
GeneralRe: MakeGenericType/CreateInstance Object to underlying Type at run-time: why this works is driving me crazy Pin
BillWoodruff28-Sep-21 10:47
mveBillWoodruff28-Sep-21 10:47 
AnswerRe: MakeGenericType/CreateInstance Object to underlying Type at run-time: why this works is driving me crazy Pin
OriginalGriff28-Sep-21 7:30
mveOriginalGriff28-Sep-21 7:30 
GeneralRe: MakeGenericType/CreateInstance Object to underlying Type at run-time: why this works is driving me crazy Pin
BillWoodruff28-Sep-21 11:19
mveBillWoodruff28-Sep-21 11:19 
GeneralRe: MakeGenericType/CreateInstance Object to underlying Type at run-time: why this works is driving me crazy Pin
OriginalGriff28-Sep-21 11:40
mveOriginalGriff28-Sep-21 11:40 
GeneralRe: MakeGenericType/CreateInstance Object to underlying Type at run-time: why this works is driving me crazy Pin
BillWoodruff29-Sep-21 1:57
mveBillWoodruff29-Sep-21 1:57 
Questionled matrix display Pin
Member 1537173026-Sep-21 8:49
MemberMember 1537173026-Sep-21 8:49 
AnswerRe: led matrix display Pin
OriginalGriff26-Sep-21 9:33
mveOriginalGriff26-Sep-21 9:33 
QuestionC# 8 nullable reference question / conundrum Pin
Super Lloyd25-Sep-21 2:36
MemberSuper Lloyd25-Sep-21 2:36 
I have my own custom list class in my utility library (provide some additional benefits like having buildin readonly view or being observable or being undoable)

and I am just migrating to .NET5 and pondering the nullable reference implication.
my type is like so:
C#
public class DocumentList<T> : IList<T>, IList
{
    //.....
}

but what of that method
C#
object? System.Collections.IList.this[int index]
{
    get { return this[index]; }
    set { this[index] = (T)value; }
}

value could be null, so .. perhaps I should throw an exception if value is null?
But what if one make a DocumentList<T?> then I expect the values to be null and should not throw an exception...

EDIT2 In fact.. that MSDN snippet below.. doesn't properly test that! Blush | :O :/

EDIT answering my own question, thanks to MSDN reference source Reference Source
C#
// Allow nulls for reference types and Nullable<U>, but not for value types.
internal static void IfNullAndNullsAreIllegalThenThrow<T>(object value, ExceptionArgument argName) 
{
    //Note that default(T) is not equal to null for value types except when T is Nullable<U>. 
    if (value == null && !(default(T) == null))
        ThrowHelper.ThrowArgumentNullException(argName);
}
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 25-Sep-21 12:45pm.

QuestionConvering time representation format Pin
Alex Dunlop22-Sep-21 0:26
MemberAlex Dunlop22-Sep-21 0:26 
AnswerRe: Convering time representation format Pin
Peter_in_278022-Sep-21 2:28
professionalPeter_in_278022-Sep-21 2:28 
AnswerRe: Convering time representation format PinPopular
Richard Deeming22-Sep-21 2:37
mveRichard Deeming22-Sep-21 2:37 
AnswerRe: Convering time representation format Pin
BillWoodruff22-Sep-21 23:00
mveBillWoodruff22-Sep-21 23:00 
AnswerRe: Convering time representation format Pin
Pete O'Hanlon23-Sep-21 3:03
mvePete O'Hanlon23-Sep-21 3:03 
GeneralRe: Convering time representation format Pin
Alex Dunlop23-Sep-21 10:22
MemberAlex Dunlop23-Sep-21 10:22 
QuestionRe: Convering time representation format Pin
Member 1532961323-Sep-21 10:32
MemberMember 1532961323-Sep-21 10:32 
GeneralRe: Convering time representation format Pin
Mycroft Holmes23-Sep-21 13:50
professionalMycroft Holmes23-Sep-21 13:50 
GeneralRe: Convering time representation format Pin
Pete O'Hanlon23-Sep-21 21:29
mvePete O'Hanlon23-Sep-21 21:29 
GeneralRe: Convering time representation format Pin
Peter_in_278023-Sep-21 22:03
professionalPeter_in_278023-Sep-21 22:03 
QuestionHow to convert Persian date representation? Pin
Alex Dunlop15-Sep-21 21:31
MemberAlex Dunlop15-Sep-21 21:31 
AnswerRe: How to convert Persian date representation? Pin
BillWoodruff15-Sep-21 22:31
mveBillWoodruff15-Sep-21 22:31 
GeneralRe: How to convert Persian date representation? Pin
Alex Dunlop15-Sep-21 23:05
MemberAlex Dunlop15-Sep-21 23:05 
GeneralRe: How to convert Persian date representation? Pin
BillWoodruff15-Sep-21 23:22
mveBillWoodruff15-Sep-21 23:22 
GeneralRe: How to convert Persian date representation? Pin
Alex Dunlop16-Sep-21 2:11
MemberAlex Dunlop16-Sep-21 2:11 
GeneralRe: How to convert Persian date representation? Pin
Richard Deeming16-Sep-21 2:26
mveRichard Deeming16-Sep-21 2:26 
GeneralRe: How to convert Persian date representation? Pin
BillWoodruff16-Sep-21 5:23
mveBillWoodruff16-Sep-21 5: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.