我想知道什么时候应该投出更好.在添加,乘法等时,C++中的隐式类型转换规则是什么.例如,
int + float = ?
int * float = ?
float * int = ?
int / float = ?
float / int = ?
int / int = ?
int ^ float = ?
Run Code Online (Sandbox Code Playgroud)
等等...
表达式是否总是被评估为更精确的类型?Java的规则有所不同吗?如果我不准确地说出这个问题,请纠正我.
如何在TypeScript或Javascript中处理类型转换?
假设我有以下TypeScript代码:
module Symbology {
export class SymbolFactory {
createStyle( symbolInfo : SymbolInfo) : any {
if (symbolInfo == null)
{
return null;
}
if (symbolInfo.symbolShapeType === "marker") {
// how to cast to MarkerSymbolInfo
return this.createMarkerStyle((MarkerSymbolInfo) symbolInfo);
}
}
createMarkerStyle(markerSymbol : MarkerSymbolInfo ): any {
throw "createMarkerStyle not implemented";
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪里SymbolInfo是基类.如何从处理类型转换SymbolInfo到MarkerSymbolInfo以打字稿或Javascript?
今天我到了The C Programming Language(第二版Brian W. Kernighan和Dennis M. Ritchie)的第167页,发现作者说我必须演员.这是本书的一部分:malloc
7.8.5存储管理
函数malloc和calloc动态获取内存块.
Run Code Online (Sandbox Code Playgroud)void *malloc(size_t n)返回指向未初始化存储的n个字节的指针,如果无法满足请求,则返回NULL.
Run Code Online (Sandbox Code Playgroud)void *calloc(size_t n, size_t size)为具有指定大小的n个对象的数组返回指向足够可用空间的指针,如果无法满足请求,则返回NULL.存储初始化为零.malloc或calloc返回的指针对于有问题的对象具有正确的对齐方式,但必须将其强制转换为适当的类型,如
Run Code Online (Sandbox Code Playgroud)int *ip; ip = (int *) calloc(n, sizeof(int));
我已经知道malloc(和它的族)返回类型void*,并且有很好的解释为什么不进行转换malloc.
但我的问题是:为什么这本书说我应该施展它?
所有这些都是平等的吗?我应该在什么情况下选择其他人?
var.ToString()
CStr的(VAR)
CType(var,String)
DirectCast(var,String)
编辑:来自NotMyself的建议......
最近我发现AndroidStudio提醒我删除一些类转换.我记得在过去,我们必须抛出findViewById的结果,但现在没有必要.
findViewById的结果仍然是View,所以我想知道为什么我们不需要转换类?
我找不到任何提到的文件,任何人都可以找到任何文件吗?
PHP有一个intval()将字符串转换为整数的函数.但是,我想事先检查字符串是否为整数,以便我可以向用户提供有用的错误消息,如果它是错误的.PHP有is_int(),但是对于字符串,它返回false "2".
PHP具有该is_numeric()函数,但如果该数字为double,则返回true.我想要一个会为double返回false的东西,但是对于int来说是真的.
例如:
my_is_int("2") == TRUE
my_is_int("2.1") == FALSE
Run Code Online (Sandbox Code Playgroud) 将a转换为a的最佳方法double是int什么?是否应该使用演员?
我有一个小表,某个字段包含" 字符变化 " 类型.我正在尝试将其更改为" 整数 ",但它给出了一个错误,即无法进行转换.
有没有办法绕过这个或者我应该创建另一个表并使用查询将记录带入其中.
该字段仅包含整数值.
NSInteger myInt = 1804809223;
NSLog(@"%i", myInt); <====
Run Code Online (Sandbox Code Playgroud)
上面的代码产生错误:
Values of type "NSInteger" should not be used as format arguments: add an explicit cast to 'long' instead.
Run Code Online (Sandbox Code Playgroud)
正确的NSLog消息实际上NSLog(@"%lg", (long) myInt);为什么我要将myInt的整数值转换为long,如果我想要显示该值?
哪些是在Typescript中从数字转换为字符串的最佳方式(如果有的话)?
var page_number:number = 3;
window.location.hash = page_number;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,编译器会抛出错误:
类型'number'不能分配给'string'类型
因为location.hash是一个字符串.
window.location.hash = ""+page_number; //casting using "" literal
window.location.hash = String(number); //casting creating using the String() function
Run Code Online (Sandbox Code Playgroud)
那么哪种方法更好?
casting ×10
.net ×2
typescript ×2
android ×1
c ×1
c# ×1
c++ ×1
fieldtype ×1
findviewbyid ×1
implicit ×1
int ×1
javascript ×1
malloc ×1
objective-c ×1
php ×1
postgresql ×1
string ×1
types ×1
vb.net ×1
xcode ×1