博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
go 基础 结构体 接口 访问权限
阅读量:4609 次
发布时间:2019-06-09

本文共 1161 字,大约阅读时间需要 3 分钟。

package Schooltype SchoolModel struct {    Name         string    Address      string    StudentCount int    Is985        bool}type ISchoolDal interface {    GetList()    Add()    Delete()}
package Schooltype SchoolDal struct {}func (o *SchoolDal) GetList() []SchoolModel {    var result []SchoolModel    if (result == nil) {        println("切片是空的")    }    var t = SchoolModel{
"江西财大", "南昌市", 1000, false} var t2 = SchoolModel{
"江西财大2", "南昌市", 1000, false} result = append(result, t) result = append(result, t2) return result}func (o *SchoolDal) Add(m SchoolModel) { println("这里是Add")}func (o *SchoolDal) Delete(m SchoolModel) { println("这里是Delete")}

 访问权限:

1.类、方法首字段小写:仅仅同一个包访问

2.反之,大写:全项目访问

package mainimport "Study1/dto"func main() {    //可以访问dto.Student  ,首字母大写    var stu = dto.Student{
"111","ligenyun",11} println(stu.Sname) //不可以访问dto.student ,首字母写写 var stu2 = dto.student{
"111","ligenyun",11} println(stu2.sname)}
package dtotype Student struct {    Sno string    Sname string    Sage int}type student2 struct {    sno string    sname string    sage int}

 

转载于:https://www.cnblogs.com/ligenyun/p/10896620.html

你可能感兴趣的文章