c# static constructor code example
Example 1: static class constructor c#
class SimpleClass
{
static readonly long baseline;
static SimpleClass()
{
baseline = DateTime.Now.Ticks;
}
}
Example 2: c# async constructor
public class ViewModel
{
public ObservableCollection<TData> Data { get; set; }
async public static Task<ViewModel> BuildViewModelAsync()
{
ObservableCollection<TData> tmpData = await GetDataTask();
return new ViewModel(tmpData);
}
private ViewModel(ObservableCollection<TData> Data)
{
this.Data = Data;
}
}