language-features

C# method call with parameter name and colon

心已入冬 提交于 2019-11-28 08:03:48
I've begun to notice at times when I'm making method calls in C# that the names of the parameters for the method I'm calling will show up in the intellisense list appended with a colon, and that I can then format the method call thusly: MethodCall(parameter1:value1, parameter2:value2); Is this a new language feature? It reminds me of the way you can call stored procedures in SQL and specify parameter names like so: spDoSomeStuff @param1 = 1, @param2 = 'other param' Is this a similar feature? If so, to what end? If not, what is it and what is it to be used for. It's a new feature. See here:

Are strings created with + concatenation stored in the string pool?

感情迁移 提交于 2019-11-28 07:44:21
For instance String s = "Hello" + " World"; I know there are two strings in the pool "Hello" and "World" but, does: "Hello World" go into the string pool? If so, what about? String s2 = new String("Hola") + new String(" Mundo"); How many strings are there in the pool in each case? Yes, if a String is formed by concatenating two String literals it will also be interned. From the JLS: Thus, the test program consisting of the compilation unit (§7.3): package testPackage; class Test { public static void main(String[] args) { String hello = "Hello", lo = "lo"; System.out.print((hello == "Hello") +

Why is there no string interpolation in Scala?

元气小坏坏 提交于 2019-11-28 07:30:43
问题 This is not just an idle quip... I wonder if anybody knows if there's an actual design reason why Scala does not support interpolation similar to Groovy and other "syntactically better Javas"? e.g. var str1 = "World"; var str2 = "Hello, ${str1}"; 回答1: The proposed solution is to omit spaces when using + . "a="+a+", b="+b It has been suggested that a Swiss keyboard layout makes this very natural to type, so the creators of Scala don't feel enough pain to justify complicating the langauge in

Why do enums have computed properties but not stored properties in Swift?

落爺英雄遲暮 提交于 2019-11-28 07:20:05
I am new to Swift and just came across this in the documentation: Computed properties are provided by classes, structures, and enumerations. Stored properties are provided only by classes and structures. Why is that? Do associated values for enum work like stored properties? It seems like they had stored properties initially - Why no stored type properties for classes in swift? enum s do have stored type properties - i.e., static properties. They don't have stored instance properties. I don't know if there is a technical reason why stored instance properties are not available for enum s. You

When to use an object or an array in javascript? [duplicate]

不问归期 提交于 2019-11-28 07:00:17
This question already has an answer here: Why can I add named properties to an array as if it were an object? 7 answers I just found out that Arrays inherit directly from Object in javascript. I'm finding the difference between an array and an object is fairly minuscule. How do i know when to use one over the other? When you need to depend on the order of the elements in the collection, use Arrays, when order is not important, use objects. Order is not guaranteed in objects, but they provide for fast key-value pair lookups. I'd use an Array [] when I'm dealing with a list of objects the same

Is the order of fields in a javascript object predictable when looping through them?

為{幸葍}努か 提交于 2019-11-28 01:48:50
In php, if you have the following code: $map = array( "first" => 1, "second" => 2 ); $map["third"] = 3; foreach($map as $key => $value) { // code } You know the entries will be listed in the order they have been added to the array. Now, can I assume the same rule applies to the Javascript equivalent below? map = { "first": 1, "second": 2 }; map["third"] = 3; for (key in map) { // code } This is a duplicate of: Elements order - for (… in …) loop in javascript Most browsers will loop through the properties in the order they were added to the object, but the Javascript standard says the order is

Is the const value parameter in definition but not declaration really C++?

孤街浪徒 提交于 2019-11-28 01:47:56
问题 This is similar to (but different from) this question. Here is some simple test code to illustrate some weirdness I have discovered with Sun CC: //---------------main.cpp #include "wtc.hpp" int main(int, char**) { testy t; t.lame(99); return 0; } //--------------wtc.hpp #ifndef WTC_HPP_INCLUDED #define WTC_HPP_INCLUDED class testy { public: void lame(int ); }; #endif //---------------wtc.cpp #include <iostream> #include "wtc.hpp" void testy::lame(const int a) { std::cout << "I was passed " <<

Are there equivalents to Ruby's method_missing in other languages?

可紊 提交于 2019-11-27 20:26:18
问题 In Ruby, objects have a handy method called method_missing which allows one to handle method calls for methods that have not even been (explicitly) defined: Invoked by Ruby when obj is sent a message it cannot handle. symbol is the symbol for the method called, and args are any arguments that were passed to it. By default, the interpreter raises an error when this method is called. However, it is possible to override the method to provide more dynamic behavior. The example below creates a

How to hide (remove) a base class's methods in C#? [duplicate]

▼魔方 西西 提交于 2019-11-27 20:10:58
This question already has an answer here: C# - Can publicly inherited methods be hidden (e.g. made private to derived class) 10 answers The essence of the problem is, given a class hierarchy like this: class A { protected void MethodToExpose() {} protected void MethodToHide(object param) {} } class B : A { new private void MethodToHide(object param) {} protected void NewMethodInB() {} } class C : B { public void DoSomething() { base.MethodToHide("the parameter"); // This still calls A.MethodToHide() base.MethodToExpose(); // This calls A.MethodToExpose(), but that's ok base.NewMethodInB(); } }

Is there any Scala feature that allows you to call a method whose name is stored in a string?

吃可爱长大的小学妹 提交于 2019-11-27 19:08:10
Assuming you have a string containing the name of a method, an object that supports that method and some arguments, is there some language feature that allows you to call that dynamically? Kind of like Ruby's send parameter. You can do this with reflection in Java: class A { def cat(s1: String, s2: String) = s1 + " " + s2 } val a = new A val hi = "Hello" val all = "World" val method = a.getClass.getMethod("cat",hi.getClass,all.getClass) method.invoke(a,hi,all) And if you want it to be easy in Scala you can make a class that does this for you, plus an implicit for conversion: case class Caller