复数可以这样写成文字:
var max2 = _fabContext.Tools
.Select(t => new
{
t.ToolId,
MaxOrder = t.ToolTask.Max(tt => (int?)tt.SortOrder),
MaxExportDate = t.ToolTask.Max(tt => (DateTime?)tt.Task.ExportDate)
})
.ToDictionary(d => d.ToolId, d => new OrderExportDate
{
Order = d.MaxOrder ?? 0,
ExportDate = d.MaxExportDate ?? DateTime.MinValue
});
与接收方整数3 + 2i # => (3+2i)
接收带有参数3
的方法+
(它本身用作复数2i
的文字)的情况在语法上有何区别? )?
答案 0 :(得分:6)
简短的回答:没有。它的工作方式是整数的import { Directive } from '@angular/core';
import { AsyncValidator, AbstractControl, ValidationErrors, NG_ASYNC_VALIDATORS, AsyncValidatorFn } from '@angular/forms';
import { Observable } from 'rxjs';
import { UserService } from '../Services/user.service';
import { map } from 'rxjs/operators';
export function UniqueUsernameValidator(userService: UserService): AsyncValidatorFn {
return (control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> => {
const q = new Promise((resolve, reject) => {
setTimeout(() => {
userService.isUsernameTaken(control.value).subscribe((data: any) => {
// console.log('top: ' + data + ' type: ' + typeof data);
if (data === false) {
resolve(null);
} else {
resolve({
usernameTaken: {
valid: true
}
});
}
}, () => {
resolve({
usernameTaken: {
valid: false
}
});
});
}, 1000);
});
return q;
};
}
@Directive({
selector: '[appUniqueUsername]',
providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: UniqueUsernameValidatorDirective, multi: true }, UserService]
})
export class UniqueUsernameValidatorDirective implements AsyncValidator {
constructor(private userService: UserService) { }
validate(control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> {
return UniqueUsernameValidator(this.userService)(control);
}
}
方法接收虚数单位并返回一个+
。因此,就字面量而言,您可以使用通常的整数和浮点字面量以及虚数字面量(例如Complex
),并通过组合它们可以构造复杂的值。
答案 1 :(得分:3)
我猜该文档具有误导性,而且看似字面的内容实际上是方法调用。我做了一个实验来证实这一点:
class Integer
alias old_plus +
def +(*args)
puts 'called with complex' if args.first.class == Complex
old_plus(*args)
end
end
8+3i
# called with complex
# => (8+3i)
(9+2i)
# called with complex
# => (9+2i)