douguabu8960 2016-05-24 08:09
浏览 31
已采纳

在Go中将varName设为int64?

How do I write the equivalent of Dim varName as int64 = value in Go?

Whenever I find myself needing to declare a variable in Go I google a lot until I find the correct syntax.

  • 写回答

1条回答 默认 最新

  • douzhushen_9776 2016-05-24 08:12
    关注

    Using a variable declaration (can be used inside functions and at the top level to create global variables):

    var i int64 = value
    

    If value is a typed int64 value, you may omit the type which will be inferred:

    var i2 = value // type is inferred
    

    Short variable declaration (may only appear inside function bodies):

    i3 := value // type is inferred
    

    Notes:

    Both with the variable declaration (without type) and with short variable declaration care must be taken if you use a value with different type - or an untyped constant. In these cases explicit type conversion may be required in order for the new variable to get the proper int64 type!

    var i4 = 4        // Wrong! i4 will be of type int
    var i5 = int64(4) // Good! i5 will be of type int64
    var i6 int64 = 4  // Also good: explicitly provided type
    i7 := 4           // Wrong! i4 will be of type int
    i8 := int64(4)    // Good! i5 will be of type int64
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路