例如,这段代码之间的区别
public Task<IList<NewsSentimentIndexes>> GetNewsSentimentIndexes(DateTime @from, DateTime to = new DateTime(), string grouping = "1h")
{
var result = _conf.BasePath
.AppendPathSegment("news-sentiment-indexes")
.SetQueryParams(new
{
from = from.ToString("s"),
to = to.ToString("s"),
grouping
});
return result
.GetStringAsync()
.ContinueWith(Desereialize<IList<NewsSentimentIndexes>>);
}
Run Code Online (Sandbox Code Playgroud)
然后
public async Task<IList<NewsSentimentIndexes>> GetNewsSentimentIndexes(DateTime @from, DateTime to = new DateTime(), string grouping = "1h")
{
var result = _conf.BasePath
.AppendPathSegment("news-sentiment-indexes")
.SetQueryParams(new
{
from = from.ToString("s"),
to = to.ToString("s"),
grouping
});
var newsStr = await result.GetStringAsync();
return JsonConvert.DeserializeObject<NewsSentimentIndexes>(newsStr);
}
Run Code Online (Sandbox Code Playgroud)
哪一个正确或更快?只是调用这个方法需要等待或只是一个任务?
c# parallel-processing asynchronous task task-parallel-library
我的所有反应形式通常包括属性和方法:
@Input()
public form: FormGroup;
public messages = VALIDATION_MESSAGES;
@Output()
public onFormSubmit: EventEmitter<any> = new EventEmitter();
@Input()
public formData;
@Input()
public controlsConfig: any;
protected abstract fb: FormBuilder;
isValidControl(controlName: string): boolean {
const control = this.form.controls[controlName];
return control.valid || control.pristine;
}
onSubmit(): void {
const form = this.form;
if(form.valid) {
this.onFormSubmit.emit(form.value);
}
}
Run Code Online (Sandbox Code Playgroud)
我在抽象课中选择了它们
export abstract class BaseReactiveForm {..}
Run Code Online (Sandbox Code Playgroud)
并继承
@Component({
selector: 'app-login-form',
templateUrl: './login-form.component.html',
styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent extends BaseReactiveForm implements OnInit {
constructor(protected fb: FormBuilder) {
super(); …Run Code Online (Sandbox Code Playgroud) 在基础LocalStorage中
public class BaseStorageRepository<T>
{
protected string OneKey = null;
protected string ListKey = null;
public async Task UpdateAllAsync(List<T> data)
{
await BlobCache.LocalMachine.InsertObject(ListKey, data);
}
}
Run Code Online (Sandbox Code Playgroud)
在孩子
public class CompanyStorageRepository : BaseStorageRepository<Company>
{
protected new string OneKey = "Company";
protected new string ListKey = "CompaniesList";
}
Run Code Online (Sandbox Code Playgroud)
执行时
UpdateAllAsync
Run Code Online (Sandbox Code Playgroud)
然后OneKey == null; 但为什么 ?毕竟,我在派生类中重新定义了属性