methods

How do I dispatch to a method based on a parameter's runtime type in C# < 4?

喜你入骨 提交于 2020-01-02 05:25:34
问题 I have an object o which guaranteed at runtime to be one of three types A , B , or C , all of which implement a common interface I . I can control I , but not A , B , or C . (Thus I could use an empty marker interface, or somehow take advantage of the similarities in the types by using the interface, but I can't add new methods or change existing ones in the types.) I also have a series of methods MethodA , MethodB , and MethodC . The runtime type of o is looked up and is then used as a

C# Pointers in a Method's arguments?

泄露秘密 提交于 2020-01-02 02:43:15
问题 I wish to directly modify a variable's value outside of a method from inside it. Pointers are the way, correct? How? 回答1: No. In c# you can apply pass by reference semantics using the ref or out modifiers: void Foo( ref string s, ref int x ) { s = "Hello World"; // caller sees the change to s x = 100; // caller sees the change to x } // or, alternatively... void Bar( out string s ) { s = "Hello World"; } The difference between these two, is that with out , the caller does not have to specify

Javascript Arrays In IE 8 issue

天涯浪子 提交于 2020-01-01 19:39:08
问题 As per what I know, arrays in Javascript is nothing but the combination of methods and objects. Now my task is to display the values of array (say y_array ) I have used for(x in y_array) and then displayed the value. In mozilla and in IE its working fine, but in IE it displays the first element of array with index as indexOf and value is indexOf(obj, from) which i dont want. I tried if(x!='indexOf') { display the array value ; } It worked and things were fine but there is extensive use of

How to generate a random number in the constructor of a class in C#

ε祈祈猫儿з 提交于 2020-01-01 19:26:29
问题 I know that it is not a good practice to call a method in the constructor of a class in C# but I stuck on something strange. My problem is that when I create an object of my class I need to assign a field in my object with a random number. for instance class RandomNumberHandler { private int randomNumber; public RandomNumberHandler() { this.randomNumber = GenerateRandomNumber(); } private int GenerateRandomNumber() { return (new Random()).Next(3000) + 1000; } } In my case I need a four digit

Is it possible to nest methods in Vue.js in order to group related methods?

不羁的心 提交于 2020-01-01 17:19:48
问题 I'd like to group some of my Vue.js methods together in a sort of "submethod" class, but I only seem to be able to have single level methods. For example, if I wanted to have a set of methods dealing purely with button actions: new Vue({ el: '#app', data: { }, methods: { buttonHandlers: { handler1: function() { dosomething; }, handler2: function() { dosomething; } } } }); I would expect to be able to then use something like: <button v-on:click="buttonHandlers.handler1">Click Me</button> but

Return more than one variable from Java method

两盒软妹~` 提交于 2020-01-01 17:08:08
问题 Sorry for stupid question... Could anybody help me with returning two variable from method (I read here and tried to recode but without result). public class FileQualityChecker { EnviroVars vars = new EnviroVars(); public int n = 0; public int z = 0; public int m = 0; String stringStatus; public void stringLenghtCheck(String pathToCheckedFile) { try{ FileInputStream fstream = new FileInputStream(pathToCheckedFile+"\\"+"Test.dat"); // Get the object of DataInputStream DataInputStream in = new

Return more than one variable from Java method

99封情书 提交于 2020-01-01 17:08:04
问题 Sorry for stupid question... Could anybody help me with returning two variable from method (I read here and tried to recode but without result). public class FileQualityChecker { EnviroVars vars = new EnviroVars(); public int n = 0; public int z = 0; public int m = 0; String stringStatus; public void stringLenghtCheck(String pathToCheckedFile) { try{ FileInputStream fstream = new FileInputStream(pathToCheckedFile+"\\"+"Test.dat"); // Get the object of DataInputStream DataInputStream in = new

Create method inside function

穿精又带淫゛_ 提交于 2020-01-01 17:07:11
问题 I am trying to create method inside a function. I can make this such a way: function sample() {}; sample.show = function() { alert() }; And I'll see the alert calling sample.show(); . But for the reason of code beautifying I want to move all method declarations inside functions. I tried that: function sample() { sample.show = function() { alert() }; } But I get: TypeError: Object function sample() has no method 'show' Another ways I tried: function sample() { this.show = function() { alert()

Calling the finish() method of an Activity from a BroadcastReceiver

隐身守侯 提交于 2020-01-01 17:06:45
问题 I have 2 Activities (Activity1, Activity2) and a BroadcastReceiver class Assume that we are now on Activity2, where I set up an AlarmManager to run at a specific time. Is there a way to call the finish() method of Activity2 within the onReceive() of the BroadcastReceiver? My goal is to return to Activity1 from Activity2 without starting a new Intent in onRecieve(). Note: The BroadcastReceiver class is not registered within the Activity of Activity2. It is registered in the AndroidManifest.xml