小编use*_*934的帖子

声明的差异:"var x = .."vs"var x; x = .."

我是C#的新手,请帮助我理解以下声明之间的区别:

var variable_name = new class_a(); // there is no error and is working fine

var variable_name; 
variable_name = new class_a(); // this line is throwing error
Run Code Online (Sandbox Code Playgroud)

当我把声明重写为

class_a variable_name; 
variable_name = new class_a(); // this is working fine
Run Code Online (Sandbox Code Playgroud)

c# variables

4
推荐指数
2
解决办法
142
查看次数

Golang 自动引用,并不总是可以获得值的地址

我是 Golang 世界的新手。我试图理解自动引用的概念。

我的困惑与以下程序有关?第一个和第二个有什么区别

  1. main 函数的第一行
age(20).print()
Run Code Online (Sandbox Code Playgroud)
  1. 第二线和第三线
myAge := age(20)
myAge.print()
Run Code Online (Sandbox Code Playgroud)

完整程序如下:

package main
import "fmt"

type age uint8

func (a *age) print() {
  fmt.Println(a)
}


func main() {
  age(20).print() // this line throws error

  // however, the below line works properly
  myAge := age(20)
  myAge.print()
}
Run Code Online (Sandbox Code Playgroud)

请帮助理解这两种方法之间的区别。我假设他们都是一样的。

types pointers reference go

3
推荐指数
1
解决办法
419
查看次数

标签 统计

c# ×1

go ×1

pointers ×1

reference ×1

types ×1

variables ×1