Search code examples
c#arraysstringobjectempty-list

C# Best practices for check objects and strings


I work on Xamarin.Forms application and want to check all possible scenarios. For example i got this code: User user= new User(); string token= string.Empty i got a instance of object user and string token in the ViewModel's Constructor. I call them like this:

user= await GetUser();token = await GetToken(); I want to check every possible return from this calls. For object check if is empty , is null or got data. for string is empty , is null or got data ? Also hint for array of object? How to organize this?


Solution

  • They return what you have defined in the method definition. The following

    Task<ReturnType> GetUser()
    

    returns an object of type ReturnType.

    To compare if an object is null: user == null. To compare if a string is null or empty: string..IsNullOrEmpty(<yourstring>)

    I suggest you to study OOP in C#