keyword

new keyword in method signature

喜夏-厌秋 提交于 2019-11-26 11:43:17
While performing a refactoring, I ended up creating a method like the example below. The datatype has been changed for simplicity's sake. I previous had an assignment statement like this: MyObject myVar = new MyObject(); It was refactored to this by accident: private static new MyObject CreateSomething() { return new MyObject{"Something New"}; } This was a result of a cut/paste error on my part, but the new keyword in private static new is valid and compiles. Question : What does the new keyword signify in a method signature? I assume it's something introduced in C# 3.0? How does this differ

When must we use extern alias keyword in C#?

折月煮酒 提交于 2019-11-26 11:28:37
问题 When must we use extern alias keyword in C#? 回答1: Basically you only really need it when you want to use two types with the same fully qualified name (same namespace, same type name) from different assemblies. You declare a different alias for each assembly, so you can then reference them via that alias. Needless to say, you should try to avoid getting into that situation to start with :) 回答2: It's there to help you hoist yourself out of a really deep hole dug by versioning. Say your first

“new” keyword in Scala

萝らか妹 提交于 2019-11-26 10:13:46
问题 I have a very simple question - when should we apply the new keyword when creating objects in Scala? Is it when we try to instantiate Java objects only? 回答1: Use the new keyword when you want to refer to a class 's own constructor: class Foo { } val f = new Foo Omit new if you are referring to the companion object's apply method: class Foo { } object Foo { def apply() = new Foo } // Both of these are legal val f = Foo() val f2 = new Foo If you've made a case class: case class Foo() Scala

Why does this Kotlin method have enclosing backticks?

走远了吗. 提交于 2019-11-26 09:50:07
问题 What are the backticks used for in the snippet below? Why add them around the fun is(amount:Int ):Boolean { ... } ? verifier.`is`(amount) 回答1: It's because is is a reserved keyword in Kotlin. Since Kotlin is supposed to be interoperable with Java and is is a valid method (identifier) name in Java, the backticks are used to escape the method so that it can be used as a method without confusing it as a keyword. Without it it will not work because it would be invalid syntax. This is highlighted

Python's equivalent of && (logical-and) in an if-statement

纵饮孤独 提交于 2019-11-26 09:41:14
Here's my code: def front_back(a, b): # +++your code here+++ if len(a) % 2 == 0 && len(b) % 2 == 0: return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] else: #todo! Not yet done. :P return I'm getting an error in the IF conditional. What am I doing wrong? You would want and instead of && . David Titarenco Python uses and and or conditionals. i.e. if foo == 'abc' and bar == 'bac' or zoo == '123': # do something Two comments: Use and and or for logical operations in Python. Use 4 spaces to indent instead of 2. You will thank yourself later because your code will look pretty

What is the difference between the “const” and “final” keywords in Dart?

[亡魂溺海] 提交于 2019-11-26 09:28:50
问题 What is the difference between const and final keyword in Dart? 回答1: There is a post on dart's website and it explains it pretty well. Final: "final" means single-assignment: a final variable or field must have an initializer. Once assigned a value, a final variable's value cannot be changed. final modifies variables . Const: "const" has a meaning that's a bit more complex and subtle in Dart. const modifies values . You can use it when creating collections, like const [1, 2, 3], and when

When should one use dynamic keyword in c# 4.0?

折月煮酒 提交于 2019-11-26 09:27:42
问题 When should one use dynamic keyword in c# 4.0?.......Any good example with dynamic keyword in c# 4.0 that explains its usage.... 回答1: Dynamic should be used only when not using it is painful . Like in MS Office libraries. In all other cases it should be avoided as compile type checking is beneficial. Following are the good situation of using dynamic. Calling javascript method from Silverlight. COM interop. Maybe reading Xml, Json without creating custom classes. 回答2: How about this? Something

Is there any reason to use the 'auto' keyword in C++03?

泪湿孤枕 提交于 2019-11-26 09:06:55
问题 Note this question was originally posted in 2009, before C++11 was ratified and before the meaning of the auto keyword was drastically changed. The answers provided pertain only to the C++03 meaning of auto -- that being a storage class specified -- and not the C++11 meaning of auto -- that being automatic type deduction. If you are looking for advice about when to use the C++11 auto , this question is not relevant to that question. For the longest time I thought there was no reason to use

Address of register variable

陌路散爱 提交于 2019-11-26 08:28:29
问题 In C, we cannot use & to find out the address of a register variable but in C++ we can do the same. Why is it legal in C++ but not in C? Can someone please explain this concept in-depth. 回答1: Here's an excerpt from Section 6.7.1 (footnote 101) of the C99 standard (pdf): The implementation may treat any register declaration simply as an auto declaration. However, whether or not addressable storage is actually used, the address of any part of an object declared with storage-class specifier

What is the difference between “AS” and “IS” in an Oracle stored procedure?

被刻印的时光 ゝ 提交于 2019-11-26 08:01:53
问题 I see Oracle procedures sometimes written with \"AS\", and sometimes with \"IS\" keyword. CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **AS** ... vs. CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **IS** ... Is there any difference between the two? Edit: Apparently, there is no functional difference between the two, but some people follow a convention to use \"AS\" when the SP is part of a package and \"IS\" when it is not. Or the other way \