草庐IT

static-constructor

全部标签

C# : assign data to properties via constructor vs. 实例化

假设我有一个Album类:publicclassAlbum{publicstringName{get;set;}publicstringArtist{get;set;}publicintYear{get;set;}publicAlbum(){}publicAlbum(stringname,stringartist,intyear){this.Name=name;this.Artist=artist;this.Year=year;}}当我想将数据分配给Album类型的对象时,接下来的两种方法有什么区别:通过构造函数varalbumData=newAlbum("Albumius","Art

c# - 如何修复 WPF 错误 : "Program does not contain a static ' Main' method suitable for an entry point"?

突然间,我的整个项目完全停止编译,并显示以下消息:Program'path_to_obj_project_folder'doesnotcontainastatic'Main'methodsuitableforanentrypoint我没有更改项目属性,只是添加了一些类,将其他一些类移到了文件夹中。它是一个WPF应用程序项目,因此应该没问题。入口点在它应该在的地方,文件App.xaml根本没有被修改:(我应该怎么做才能让它重新工作?注意供引用:如果重命名App.xaml可能会发生这种情况。正如OP所述,App.xaml没有改变;但是,这是为重命名App.xaml的任何人添加的。

c# - C# 中的 "static method"是什么?

在方法中添加static关键字意味着什么?publicstaticvoiddoSomething(){//Well,dosomething!}你能在类中添加static关键字吗?那这意味着什么? 最佳答案 与常规(实例)函数不同,static函数不与类的实例相关联。static类是只能包含static成员的类,因此不能被实例化。例如:classSomeClass{publicintInstanceMethod(){return1;}publicstaticintStaticMethod(){return42;}}为了调用Instan

c# - 为什么我不能有 "public static const string S = "东西”;在我的类(class)?

尝试编译我的类时出现错误:Theconstant'NamespaceName.ClassName.CONST_NAME'cannotbemarkedstatic.在线:publicstaticconststringCONST_NAME="blah";我可以一直用Java做到这一点。我究竟做错了什么?为什么它不允许我这样做? 最佳答案 const对象总是static。 关于c#-为什么我不能有"publicstaticconststringS="东西”;在我的类(class)?,我们在St

javascript - 类型错误 : undefined is not a constructor

我是Angular的新手,我仍在努力弄清楚其中的大部分内容。我正在使用从YeomanGenerator生成的Angular1.5.8编写一些测试。具体来说,我正在尝试弄清楚如何操纵$httpBackend结果(我不确定这是否重要)...在我的app.js文件中,我有以下代码:.run(['$rootScope','$location','breadcrumbService',function($rootScope,$location,breadcrumbService){$rootScope.$on('$viewContentLoaded',function(){jQuery('htm

javascript - Babel 和 ES6 出现意外的 "Uncaught TypeError: XXX is not a constructor"错误

我正在尝试Webpack,并且正在尝试thistutorial中的说明,给予或接受一些定制的东西。这确实是简单的代码,但我对这个错误感到很困惑,觉得这是我错过的一些愚蠢的事情。我定义了两个ES6类,每个对应一个Handlebars模板,我的应用程序的入口点应该用它们的内容替换索引文件中的占位符HTML:入口点:import'./bloj.less'//Ifwehavealink,rendertheButtoncomponentonitif(document.querySelectorAll('a').length){require.ensure([],()=>{constButton=

javascript - ES6 模块 : Export single class of static methods OR multiple individual methods

我正在使用ECMAScript6模块。从以下选项中从模块导出/导入多个方法的正确方法是什么?单类静态方法://------myClass.js------exportdefaultclassmyClass{staticmyMethod1(){console.log('foo');}staticmyMethod2(args...){console.log('bar');}}//------app.js------importmyClassfrom'myClass';myClass.myMethod1();//foo多个导出方法://------myMethods.js------expo

javascript - 错误 : *. default is not a constructor

在测试从typescript文件转译的一些javascript代码时,出现以下错误。这里是错误:Error:_mapAction2.defaultisnotaconstructor这是导致错误的代码行:varmapAction=newMapAction(MapActionType.POLYGONDRAGGED,[]);这是原始的typescript文件ma​​p-action.ts:import{IMapAction}from'./imap-action';import{MapActionType}from'./map-action-type.enum';import{LatLngLi

Javascript 继承 : call super-constructor or use prototype chain?

最近我读到有关MDC中JavaScript调用的用法https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call下面例子中的一个链接,我还是没看懂。为什么他们在这里使用继承Prod_dept.prototype=newProduct();有这个必要吗?因为在中有对超构造函数的调用Prod_dept()不管怎样,就这样Product.call这只是出于普遍行为吗?什么时候使用超构造函数调用或使用原型(prototype)链更好?functionProduct(name,value){t

javascript - 如何在 ES6 类中创建 "public static field"?

我正在制作一个Javascript类,我希望有一个像Java中那样的公共(public)静态字段。这是相关代码:exportdefaultclassAgent{CIRCLE:1,SQUARE:2,...这是我得到的错误:line2,col11,Classpropertiesmustbemethods.Expected'('butinsteadsaw':'.看起来ES6模块不允许这样做。有没有办法获得所需的行为,还是我必须编写一个getter? 最佳答案 您使用访问器和“静态”关键字制作“公共(public)静态字段”:classAg