Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# async constructor

public class ViewModel       
{       
    public ObservableCollection<TData> Data { get; set; }       

    //static async method that behave like a constructor       
    async public static Task<ViewModel> BuildViewModelAsync()  
    {       
        ObservableCollection<TData> tmpData = await GetDataTask();  
        return new ViewModel(tmpData);
    }       

    // private constructor called by the async method
    private ViewModel(ObservableCollection<TData> Data)
    {
        this.Data = Data;   
    }
}  
Comment

c# async task constructor

Yes, they can, but they shouldn't.
Comment

PREVIOUS NEXT
Code Example
Csharp :: action c# 
Csharp :: while loop in c# 
Csharp :: entity 
Csharp :: access denied tring to save a file uwp xamarin 
Csharp :: C# date type no time 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: jtoken toobject is not exact double 
Csharp :: c# int to short 
Csharp :: if exercises c# 
Csharp :: How to build a rest component with very long process 
Csharp :: unity mathf.clamp 
Csharp :: c# create default instance of type 
Csharp :: no cameras rendering unity 
Csharp :: Code snipet for jump script unity 2d 
Csharp :: windows forms webbrowser goforward 
Csharp :: wpf mvvm crud example 
Csharp :: how to assign 2d physics material through script 
Csharp :: c# panel to graphics 
Csharp :: Unity how get Attributes of a gameObject 
Csharp :: ef core index attribute 
Csharp :: F# tuple get item 
Csharp :: crystal report error webconfig reference 
Csharp :: list to array f# 
Csharp :: how long dose it take for formate a currupt USB? 
Csharp :: SendFileAsync discord 
Csharp :: unittest servicector automapper 
Csharp :: Unity mousetoterrainposition 
Csharp :: c# nunit initialize variables 
Csharp :: call Textboxfor in cs 
Csharp :: c# load a file into binary buffer 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =