Mricrosoft XNA教育目录的片段:
/// <summary>
/// Draws the control, using SpriteBatch and SpriteFont.
/// </summary>
protected override void Draw()
{
const string message = "Hello, World!\n" +
"\n" +
"I'm an XNA Framework GraphicsDevice,\n" +
"running inside a WinForms application.\n" +
"\n" +
"This text is drawn using SpriteBatch,\n" +
"with a SpriteFont that was loaded\n" +
"through the ContentManager.\n" +
"\n" +
"The pane to my right contains a\n" +
"spinning 3D triangle.";
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.DrawString(font, message, new Vector2(23, 23), Color.White);
spriteBatch.End();
}
每秒调用60次。在抽奖中分配消息是否有任何性能开销?它是否像我将它移动到静态助手类一样?据我所知,成本表达式由C#编译器评估。 const修饰符在这里改变了什么?
答案 0 :(得分:5)
const只评估一次。通过将其移动到静态变量中,你什么都得不到。
答案 1 :(得分:1)
没有为您优化它。