我是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) 我是 Golang 世界的新手。我试图理解自动引用的概念。
我的困惑与以下程序有关?第一个和第二个有什么区别
age(20).print()
Run Code Online (Sandbox Code Playgroud)
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)
请帮助理解这两种方法之间的区别。我假设他们都是一样的。