Click here to Skip to main content
15,446,510 members
Home / Discussions / Mobile
   

Mobile

 
PinnedForum Guidelines - PLEASE READ PinPopular
Chris Maunder28-Jul-09 2:38
cofounderChris Maunder28-Jul-09 2:38 
QuestionXamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Luis M. Rojas22-Jul-22 7:18
MemberLuis M. Rojas22-Jul-22 7:18 
AnswerRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Richard MacCutchan22-Jul-22 21:23
mveRichard MacCutchan22-Jul-22 21:23 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Luis M. Rojas23-Jul-22 3:34
MemberLuis M. Rojas23-Jul-22 3:34 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Richard MacCutchan23-Jul-22 8:14
mveRichard MacCutchan23-Jul-22 8:14 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Luis M. Rojas23-Jul-22 11:59
MemberLuis M. Rojas23-Jul-22 11:59 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Richard MacCutchan23-Jul-22 20:50
mveRichard MacCutchan23-Jul-22 20:50 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Luis M. Rojas25-Jul-22 3:21
MemberLuis M. Rojas25-Jul-22 3:21 
GeneralRe: Xamarin using C#: System.NullReferenceException: 'Object reference not set to an instance of an object.' Pin
Richard Deeming25-Jul-22 4:37
mveRichard Deeming25-Jul-22 4:37 
NB: The as operator can and will return null if the object you're trying to cast cannot be converted to the target type.
Type-testing operators and cast expression - C# reference | Microsoft Docs[^]

You use as when you're not sure whether the object can be converted to the specified type; in which case, you should always check for null before using the variable. Using T y = x as T; without then checking for y == null is always a mistake.

When you're certain that the object will be of the desired type, you use a cast expression instead: T y = (T)x; In this case, there is no need to check for null, since the runtime would throw an exception if the conversion cannot be performed.

However, in this case, it would be far better to simply use the WebRequest.CreateHttp method, which has been available since .NET 4.5, and already returns the correct type:
WebRequest.CreateHttp Method (System.Net) | Microsoft Docs[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionMessage Closed Pin
25-Mar-22 7:38
MemberMember 1557910425-Mar-22 7:38 
QuestionIs is realistic to make money from a small mobile/tablet app? Pin
Patrick Skelton20-Mar-22 0:54
MemberPatrick Skelton20-Mar-22 0:54 
AnswerRe: Is is realistic to make money from a small mobile/tablet app? Pin
Richard MacCutchan20-Mar-22 2:17
mveRichard MacCutchan20-Mar-22 2:17 
GeneralRe: Is is realistic to make money from a small mobile/tablet app? Pin
Patrick Skelton21-Mar-22 21:26
MemberPatrick Skelton21-Mar-22 21:26 
AnswerRe: Is is realistic to make money from a small mobile/tablet app? Pin
Gerry Schmitz20-Mar-22 4:32
mveGerry Schmitz20-Mar-22 4:32 
GeneralRe: Is is realistic to make money from a small mobile/tablet app? Pin
Patrick Skelton21-Mar-22 21:33
MemberPatrick Skelton21-Mar-22 21:33 
GeneralRe: Is is realistic to make money from a small mobile/tablet app? Pin
Member 150787168-Aug-22 16:50
MemberMember 150787168-Aug-22 16:50 
AnswerRe: Is is realistic to make money from a small mobile/tablet app? Pin
Member 150787168-Aug-22 16:44
MemberMember 150787168-Aug-22 16:44 
QuestionHow to get started - app android and ios Pin
David Mikkelsen 20212-Mar-22 8:06
MemberDavid Mikkelsen 20212-Mar-22 8:06 
GeneralRe: How to get started - app android and ios Pin
jaket-cp14-Mar-22 4:43
Memberjaket-cp14-Mar-22 4:43 
AnswerMessage Closed Pin
20-Apr-22 22:46
MemberLinda Hartley20-Apr-22 22:46 
AnswerRe: How to get started - app android and ios Pin
kevin james Jun202218-Aug-22 6:48
Memberkevin james Jun202218-Aug-22 6:48 
GeneralRe: Why to Choose Mobile App Company in India for best out put? Pin
Member 150787168-Aug-22 17:01
MemberMember 150787168-Aug-22 17:01 
GeneralRe: Why to Choose Mobile App Company in India for best out put? Pin
Richard Deeming8-Aug-22 22:06
mveRichard Deeming8-Aug-22 22:06 
GeneralRe: Why to Choose Mobile App Company in India for best out put? Pin
Richard MacCutchan9-Aug-22 0:15
mveRichard MacCutchan9-Aug-22 0:15 
GeneralRe: Why to Choose Mobile App Company in India for best out put? Pin
Richard Deeming9-Aug-22 0:17
mveRichard Deeming9-Aug-22 0:17 

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.