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 :: ontriggerenter 
Csharp :: HTTP Error 500.35 - ASP.NET Core does not support multiple apps in the same app pool 
Csharp :: serilog .net 6 
Csharp :: get file name from stream c# 
Csharp :: C# loop through the registry searching for keys containing 
Csharp :: c# gettype 
Csharp :: convert list string to list enum c# 
Csharp :: player input manager join manually 
Csharp :: unity audio source 
Csharp :: math with c sharp 
Csharp :: how to mock http client c# 
Csharp :: c# get smallest of 3 numbers 
Csharp :: c# read xml tag value 
Csharp :: .net json result status code not working 
Csharp :: C# The request was aborted: Could not create SSL/TLS secure 
Csharp :: read json from assets c# 
Csharp :: cross thread exception in c# control 
Csharp :: async where linq 
Csharp :: Rotating an object in Unity usign Physics 
Csharp :: flat view player movement script 
Csharp :: how to make a character jump c# 
Csharp :: v-slot 
Csharp :: c# dictionary check if value exists 
Csharp :: wpf keydown detect if control key is down 
Csharp :: unity c# image invisible 
Csharp :: dapper get list 
Csharp :: c# resize multidimensional array 
Csharp :: .net core get runtime version 
Csharp :: c# while loops 
Csharp :: c# textbox kodu 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =