Class F#在方法中为类成员赋值
我在VS2010中玩F#,我不太明白如何给类中的成员赋值Class F#在方法中为类成员赋值,class,syntax,f#,Class,Syntax,F#,我在VS2010中玩F#,我不太明白如何给类中的成员赋值 type SampleGame = class inherit Game override Game.Initialize() = spriteBatch <- new SpriteBatch(this.GraphicsDevice) base.Initialize() val mutable spriteBatch : SpriteBatch end
type SampleGame =
class
inherit Game
override Game.Initialize() =
spriteBatch <- new SpriteBatch(this.GraphicsDevice)
base.Initialize()
val mutable spriteBatch : SpriteBatch
end
type SampleGame=
阶级
继承游戏
覆盖游戏。初始化()
spriteBatch我认为在使用变量之前必须声明变量
type SampleGame =
class
inherit Game
val mutable spriteBatch : SpriteBatch
override Game.Initialize() =
spriteBatch <- new SpriteBatch(this.GraphicsDevice)
base.Initialize()
end
type SampleGame=
阶级
继承游戏
val可变spriteBatch:spriteBatch
覆盖游戏。初始化()
spriteBatch我认为在使用变量之前必须声明变量
type SampleGame =
class
inherit Game
val mutable spriteBatch : SpriteBatch
override Game.Initialize() =
spriteBatch <- new SpriteBatch(this.GraphicsDevice)
base.Initialize()
end
type SampleGame=
阶级
继承游戏
val可变spriteBatch:spriteBatch
覆盖游戏。初始化()
spriteBatch您应该更喜欢这种语法来定义类
type SampleGame() =
inherit Game()
let mutable spriteBatch : SpriteBatch = null
override this.Initialize() =
spriteBatch <- new SpriteBatch(this.GraphicsDevice)
base.Initialize()
type SampleGame()=
继承游戏()
让可变spriteBatch:spriteBatch=null
重写此。初始化()
spriteBatch您应该更喜欢这种语法来定义类
type SampleGame() =
inherit Game()
let mutable spriteBatch : SpriteBatch = null
override this.Initialize() =
spriteBatch <- new SpriteBatch(this.GraphicsDevice)
base.Initialize()
type SampleGame()=
继承游戏()
让可变spriteBatch:spriteBatch=null
重写此。初始化()
雪碧棒嗯。。。你可能是对的。我想我被C宠坏了,让我在任何地方声明我的变量!只是测试了一下,没用。具体错误是“值或构造函数”spriteBatch“没有定义嗯…你可能是对的。我想我被C宠坏了,让我在任何地方声明变量!只是测试了它,没有帮助。具体错误是“值或构造函数”spriteBatch“没有定义我只是尝试了一下,它给了我错误“除非使用隐式构造序列,否则类定义中不允许使用'let'和'do'绑定。”如果我尝试将paren附加到“继承游戏”部分,它会说“此'inherit'构造调用不是隐式构造序列的一部分。此时只应指定继承的类型…”。听起来您错过了SampleGame之后的第一组空参数。(这些定义构造函数的参数是“隐式构造序列”的开始部分。)我一直忘记我们有文档!为了完整性:我刚试过,它给了我错误“除非使用隐式构造序列,否则类定义中不允许使用“let”和“do”绑定。”如果我尝试将paren附加到“inherit Game”部分,它会说“此“inherit”构造调用不是隐式构造序列的一部分。此时只应指定继承的类型…”。听起来您错过了SampleGame之后的第一组空参数(这些定义构造函数的参数是“隐式构造序列”的开始)。我一直忘记我们有文档!为了完整性: