Tag: 静态

为什么接口不能指定静态方法?

我知道这个问题已经被反复询问,但我似乎无法find足够的答案。 所以要说清楚我想知道的是什么,我将分成两个问题: 为什么不能有静态方法签名? 我会尝试抢占非答案,问为什么在世界上我想要做到这一点如下:我想能够静态调用SqliteCodeGenerator和MssqlCodeGenerator GetDbConnectionType() : interface ICodeGenerator { // this is the method I would like to be static: string GetDbConnectionType(); } abstract class CodeGeneratorBase : ICodeGenerator { public abstract string GetDbConnectionType(); public void GenerateSomeCode(StringBuilder s) { s.AppendLine("var foo = new " + GetDbConnectionType() + "();"); } } class SqliteCodeGenerator : CodeGeneratorBase { public […]

在定义cachingvariables时,在objective-c中使用static关键字

我正在看下面的苹果示例源代码: /* Cache the formatter. Normally you would use one of the date formatter styles (such as NSDateFormatterShortStyle), but here we want a specific format that excludes seconds. */ static NSDateFormatter *dateFormatter = nil; if (dateFormatter == nil) { dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"h:mm a"]; } 试图弄清楚: 为什么使用static关键字? 如果在每次调用方法时将其设置为nil,这与caching的variables相等。 代码来自Tableview Suite演示中的示例4

什么时候在全局variables之前使用static关键字?

有人可以解释什么时候你应该使用静态关键字之前全局variables或常量定义在头文件? 例如,让我说我有一个头文件的行: const float kGameSpriteWidth = 12.0f; 应该在const前面有static吗? 什么是使用static一些最佳实践?

C ++单例与全局静态对象

我的一个朋友今天问我为什么他更喜欢使用singleton而不是全局静态对象呢? 我开始解释的方式是,单身可以有状态与静态全局对象不会…但后来我不确定..因为这在C ++ ..(我来自C#) 彼此有什么优势? (在C ++中)

c#:控制台应用程序 – 静态方法

为什么在C#中,控制台应用程序中,在“程序”类中,这是默认的,所有的方法都必须是静态的 static void Main(string[] args)

麻烦声明静态枚举,C#

嗨,我想解散静态枚举像这样: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace Lds.CM.MyApp.Controllers { public class MenuBarsController : Controller { // Menu Bar enums public static enum ProfileMenuBarTab { MainProfile, Edit, photoGallery } public ActionResult cpTopMenuBar(string tabSelected) { … “但我得到以下错误:”修饰符'静态'是不适用于这个项目。“我知道这是简单的,但我似乎无法看到的问题,非常感谢!

C ++中静态对象的破坏顺序

我可以控制静态对象被破坏的顺序吗? 有什么办法来执行我想要的命令吗? 例如,以某种方式指定我想要最后销毁某个对象,或者至less在另一个静态对象之后?

静态与全局

如果我有下面的C文件,那么i和j什么区别? #include <stdio.h> #include <stdlib.h> static int i; int j; int main () { //Some implementation }

Django加载块的CSS

我有几页。 对于每个页面我需要加载独特的CSS。 对于所有静态文件,我使用这个 。 在index.html的头部我有: {% block css %} {% endblock %} 但是,例如,在contact.html中我使用: {% extends "index.html" %} {% block css %} <link rel="stylesheet" href="{% static "css/contact.css" %}" type="text/css" /> {% endblock %} 和它的打印错误: 无效块标记:“静态”,预计“endblock” 。 如何解决它?

在C#中声明一个const double ?

我有几个常量,我使用,我的计划是把他们在一个双数的常量数组,但编译器不会让我。 我试过这样的声明: const double[] arr = {1, 2, 3, 4, 5, 6, 73, 8, 9 }; 然后我决定把它声明为static: static readonly double[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; 但问题依然存在。 为什么编译器不能让我声明一个常量值数组? 还是会的,我只是不知道如何?