What is the proper way to declare a Microsoft class to use in my code. The quick and dirty way I am doing it here, I know, is not correct

complete

Active member
Joined
Oct 24, 2012
Messages
33
Programming Experience
3-5
What is the proper way to declare a Microsoft class to use in my code. The quick and dirty way I am doing it here, I know, is not correct

> Microsoft SharePoint.Client.List newList = null;

I think it is something like this

> Microsoft.SharePoint.Client.List newList = new Microsoft.SharePoint.Client.List();

Basically, the warning message I am getting makes me uncomfortable:

proper-way.png
 
Solution
It's because you are trying to use "new" C# that has nullable checks with a library that was originally written for "old" C# where all reference types could potentially be null.

So with new C# you would write:
C#:
Microsoft.SharePoint.Client.List? newList1 = null;
where as old C# would just let you get away with:
C#:
Microsoft.SharePoint.Client.List newList1 = null;

In general, in C# you don't need to pre-assign null to variables like you would in C++. In C#, reference types default to null, and value types default to their "zero" value.
It's because you are trying to use "new" C# that has nullable checks with a library that was originally written for "old" C# where all reference types could potentially be null.

So with new C# you would write:
C#:
Microsoft.SharePoint.Client.List? newList1 = null;
where as old C# would just let you get away with:
C#:
Microsoft.SharePoint.Client.List newList1 = null;

In general, in C# you don't need to pre-assign null to variables like you would in C++. In C#, reference types default to null, and value types default to their "zero" value.
 
Solution
Thank you for your response !!
I will do that '?' thing you suggested.

Update, the squiggly line under the null reference went away which tells me your suggestion was spot on accurate.

Thanks again !!
 

Latest posts

Back
Top Bottom