开发者

SQLite & Int64 to Int32 cast in C#

Good night,

I have an SQLite query which I am executing in C# using the ExecuteScalar() command. The result in an Object type variable which is in fact a value of type Int64. As I need to cast it to an Int32, I tried first using Convert.ToInt32 and now开发者_运维问答 I am using (Int32)(Int64)Object, although I get the same performance with both. The question is that this kind of cast seems to take an additional 6ms to perform, and the method concerned is critical code which should be executed as fast as possible... Is there any way to perform this cast faster, by using, for example, bit operators or some other method?

Just in case this is not possible, I really don't understand why the result of the query is an Int64... is there any way I can force it to be an Int32?

Thank you very much.


You could use a data reader instead of execute scalar and call the static getint32 function. Not sure if it would be faster though.

Alternatively, you can cast your result in the sql query before it is returned. Again, this may actually decrease the overall performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜