浅析Go语言编程当中映射和方法的基本使用
映射 定义映射 复制代码 代码如下: /* declare a variable,by default map will be nil*/ /* define the map as nil map can not be assigned any value*/ 例子 下面的例子说明创建和映射的使用。 复制代码 代码如下: package main import "fmt" func main { 让我们编译和运行上面的程序,这将产生以下结果: Capital of India is New Delhi Capital of France is Paris Capital of Italy is Rome Capital of Japan is Tokyo Capital of United States is not present delete() 函数 复制代码 代码如下: package main import "fmt" func main { 让我们编译和运行上面的程序,这将产生以下结果: Original Map Capital of France is Paris Capital of Italy is Rome Capital of Japan is Tokyo Capital of India is New Delhi Entry for France is deleted Updated Map Capital of India is New Delhi Capital of Italy is Rome Capital of Japan is Tokyo 方法 语法 复制代码 代码如下: func (variable_name variable_data_type) function_name() [return_type]{ /* function body*/ } package main import ( /* define a circle */ /* define a method for circle */ func main(){ 当上述代码被编译和执行时,它产生了以下结果: Circle area: 78.539816 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |