struct account { var owner: string = "tony" //声明实例属性账户名 static var interestrate: double = 0.0668 //声明静态属性利率 static func interestby(amount: double) -> double {//定义静态方法 return interestrate * amount } func messagewith(amount: double) -> string { //定义实例方法 let interest = account.interestby(amount) return "\(self.owner) 的利息是\(interest)" } }
enum account { case 中国银行 case 中国工商银行 case 中国建设银行 case 中国农业银行 static var interestrate: double = 0.0668 //声明静态属性利率 static func interestby(amount: double) -> double { //定义静态方法 return interestrate * amount } }
class account { var owner: string = "tony" //账户名 //可以换成static class func interestby(amount: double) -> double {//使用关键字class定义静态方法 return 0.08886 * amount } } //调用静态方法 print(account.interestby(10_000.00)) //调用静态方法
如对本文有疑问, 点击进行留言回复!!
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
微信公众号ios和android验签的区别(解决ios验签报错)
IOS系统中使用new Date()报错valid Date
网友评论