Questions tagged [methods]
A method is a block of code that performs a task and is associated with a class or an object. It is related to the non-object-oriented concepts of functions and procedures.
methods
30,450 questions
-5
votes
0
answers
92
views
having a very hard time with Excel addpicture [duplicate]
I am having a very hard time coding the addpicture method. I am running Excel 2019, and trying to get a picture inserted into a cell, as in not a link, and not floating.
Here is my code:
...
Advice
0
votes
2
replies
85
views
Method-body equivalent of lambda expression
Following is a part of the execution sequence when a middleware gets configured in ASP.NET Core -
...
2
votes
1
answer
127
views
Inheriting optional methods from a type
I'd like to have a class with a bunch of optional methods derived from some type, then implement some of those in some subclasses:
...
5
votes
1
answer
90
views
Externally provided method not receiving self
While methods are usually defined inside the class block with def func(self, ...):, this is not required:
...
Advice
0
votes
4
replies
117
views
Does the finally block run when returning inside try, and what happens if finally also returns?
I have a question about how try/finally behaves when using return statements in C#.
Consider ...
-8
votes
1
answer
153
views
Wrapping a method in a try-catch block but unsure where to declare a char variable
I have this method in my program, it is meant to register the gender of the user for later on in the program (with Male and Female as the only valid options):
...
-8
votes
1
answer
106
views
Formatting the first symbol of a string to be upper case - a private method or formatting on the go? [closed]
In a class that has a bunch of functions, should I be making a separate private method specifically for formatting or should I just be formatting in every function that requires a string to be ...
3
votes
1
answer
67
views
Typescript method overload lost
I'm using typescript in a project which uses BackboneJS and in a certain case, a method overload gets lost.
I narrowed it down to this case:
...
0
votes
1
answer
67
views
How can I forbid method redefenition in TCL OO class?
I would like that method redefenition would result in failure and script execution stop. Like any other common error.
In the following example I want to see that method print cannot be redefined.
<...
3
votes
1
answer
204
views
What does 0 mean in someList.toArray(new AnotherClass[0])?
In Java we have toArray() method which will return Object[]. If I want to return another data type I need to pass it to parameters like this
...
0
votes
0
answers
157
views
Detect unimplemented class methods without a program failing to link
Suppose I am working on a library with a decent number of classes, most of them having a bunch of methods, in addition to the basic ctors and dtor. For reasons, the method implementations are spread ...
1
vote
1
answer
78
views
How to type class method arguments based on function arguments passed to class constructor
I have class example:
...
0
votes
1
answer
104
views
PHP vs C++: How do I declare class constants which are used in method calls in C++? [duplicate]
I come from PHP where I usually never have global constants. For instance, if I have the class Users and the method ...
0
votes
3
answers
127
views
Minifiying javascript file with webpack breaks vue functionality (specifically with method calls on class instance)
I am working on an ASP.NET project that uses Vue.js and jQuery. I have a JavaScript file (fields.js) that defines several classes (e.g., Users, Fields) and initializes a Vue instance. When I use the ...
-9
votes
1
answer
153
views
Using the .find() function in a loop [closed]
I was trying to get the last word of the sentence using the .find() method in a loop.
My code:
...
1
vote
2
answers
118
views
Adding decorator to a python class
I have a few methods that require a certain condition to be applied to function properly. To avoid code repetition I've created a decorator to check if this condition is applied and only then execute ...
2
votes
1
answer
77
views
How to pass any object as a classmethod's first argument - circumvent injection of class argument
Passing a class, or a totally different object, as the first argument to method is easy:
...
1
vote
1
answer
72
views
Methods for a TypeScript type alias
I have this Dir type alias that is a set of 8 cardinal directions, used as an enum:
...
0
votes
1
answer
115
views
0
votes
1
answer
57
views
Two Separate struct Methods Modifying another Struct Field [duplicate]
I want to know how two separate struct methods can modify a field in third struct.
What I'm getting now is {[20]}
{[30]}
Like the two methods on B and C should modify the list field of A and the ...
1
vote
2
answers
106
views
How can I calculate 0 factorial in a basic factorial code in Java
Here is a basic Java Code which I wrote. I want to know how I can calculate 0! as it can calculate every other number.
...
1
vote
0
answers
80
views
What is the best method return type to support my PowerShell cmdlets
I have created a module with a custom class that generates specific [Node] objects. The module has another class with an method that gets a single specific Node ...
1
vote
1
answer
126
views
NetBeans is glitching and calling a method that isn't there
I'm doing homework for a Data Structures class and making a 2-3 tree in NetBeans, but there's a glitch that keeps happening where a method is called twice, but the second time, it's being called by a ...
0
votes
3
answers
142
views
How do I give the possibility to call multiple optional methods onto one parameter in a constructor in JAVA
I would like to make a constructor with an optional parameter, to avoid giving in Strings all the time, because I need to use the constructor like a thousand times, so I would like to call methods ...
-2
votes
2
answers
93
views
How do I call the method from a class that creates other objects? [closed]
I have five classes. My Main class, a form class, two subclasses that extend the form class and a createForm class I am forced to use to create new instances of the subclass.
...
0
votes
1
answer
177
views
Intercepting and redirecting calls of a nested class structure in python
I have a very deeply nested class structure spanning multiple files and multiple levels of definitions. You can imagine this as a class describing some hardware system where each hardware component is ...
-3
votes
4
answers
122
views
Needed Aid With Java Schoolwork - Containing Arrays & Array Searchs
Current Outputs:
Is [1, 2, 3] found in [1, 2, 1, 2, 3] ? >>> false
Is [1, 1, 3] found in [1, 2, 1, 2, 3] ? >>> false
Needed Outputs:
...
1
vote
2
answers
60
views
Laravel error whit undefinde variables pass to view
im new to laravel and im getting an error Undefined variable $columnCounts passed to view.
i have a index() method that call 2 other method of the same ...
-1
votes
1
answer
81
views
I'm making a Guess a Number Game in Java Swing and I'm having problems the JButton [duplicate]
The program technically works, but I keep getting the error:
"Cannot invoke "javax.swing.JButton.addActionListener(java.awt.event.ActionListener)" because "this.check" is null&...
0
votes
0
answers
63
views
Jacobi method converges faster than Gauss-Seidel in case of Laplace equation
It is need to solve the problem using the Jacobi method: d^T/dx^2 + d^2T/dy^2 = 0 with conditions at the boundaries of the square:
T(0, y) = 1, T(x, 1) = 1, dT/dx(1, y) = 1 - y, dT/dy(x, 0) = x.
...
1
vote
1
answer
113
views
Why can't I add default-argument to my lambda function parameters (or is there an alternative way to do it)?
So I have a method with simple lambda functions I use to update my weights and I want to try different functions but I also want to have default parameter for the decay:
...
-4
votes
1
answer
165
views
Unexpected behavior of Global Scope Variable in C#
I have been trying to understand two code blocks.
The first code block:
...
0
votes
0
answers
40
views
JS `os` method not returning any data in Vite project
My goal is to collect and graph CPU usage for the host. I have a simple Vite project and am using vite-plugin-node-polyfills to try to use the ...
-2
votes
1
answer
79
views
In Python, how can I find the class in which a method is defined? [duplicate]
If I have a class hierarchy in Python (we can assume there's no multiple inheritance), how can I find the class in which a method is defined? For example:
...
-4
votes
1
answer
80
views
Creating a bubblesort method to sort a list in C# [closed]
I seem to have a problem to sort my list (cities and temperatures) from coldest to warmest. Here is the code for the method.
...
1
vote
2
answers
85
views
How to set values of matrices with the help of methods in c?
Ive been trying to set the values of matrices with the help of methods that take pointers, But I am unable to do this. The setMatrixValue method stops working when the loop reaches the second row. The ...
0
votes
1
answer
124
views
How can I use a method outside of a class without using static keyword in C#?
I'm beginner in C# programming,
What I want to do is use a method out side of the class but method is unreachable, I cant do it without static keyword and I dont want to use static keyword because I'm ...
1
vote
1
answer
113
views
SwiftUI onDelete() need the row ID from the IndexSet
I'm trying to use SwiftUI with onDelete() method to capture the TodoItem.id of the row that was swiped. I've set up an array ...
1
vote
1
answer
71
views
Trying to decipher what this code does and why [PANDAS] (astype method)
So I'm an economics undergrad trying to learn some pandas for data manipulation.
...
3
votes
3
answers
229
views
In C++, is there a way to provide object member name as template parameter?
I have multiple classes C1, C2, etc, each has different members variables, ex: C1M1, C1M2, C2N1, C2N2. And I have a pointer to data that could be an object of C1, C2 based on initial bytes.
Is there a ...
2
votes
1
answer
120
views
Issue with recursive method to extract substring between outer parentheses
I'm working on a recursive method clean that extracts the substring inside the outermost parentheses of a string, without the parentheses themselves. The method works as expected, but omits the ...
1
vote
0
answers
27
views
How come the clip.getLevel(); method is only returning -1.0?
I am trying to make an audio visualizer on Java, and I am attempting to use the .getLevel() function of the Clip clip; thing. Yet it is only returning -1.0, nothing else. Here is my code:
...
0
votes
2
answers
161
views
Why C# Error CS0103 when calling a method from another namespace when the namespace was rightly specified?
I created an age conditional "Hello World!". You type in your name, then I ask your age and if you're under 8, I ask you to leave the computer because you should just go play outside.
Here's ...
-4
votes
2
answers
109
views
Return values beside each other
I've been assigned a temperature conversion assignment that requires values to be printed next to each other, using two static methods and a single System.out.print statement. For reference, I've ...
-1
votes
1
answer
220
views
Make the code from a WooCommerce Payment Plugin HPOS Compatible [closed]
I'm trying to make a plugin HPOS compatible.
Below is the new code that I edited and then the old one.
This is my code attempt (new replaced code):
...
1
vote
0
answers
81
views
How to highlight a specific IME in ACTION_INPUT_METHOD_SETTINGS for android
When I call the android settings menu to enable my input method, I would like the menu to flash to highlight the correct item in the list for my keyboard. I saw this happen when installing another ...
0
votes
1
answer
59
views
How to get a function call argument string name, inside the same function. Using that as "extra parameter", avoiding adding an extra parameter [duplicate]
Having any Python function as:
def function1(param1, param2):
#...
return 0
How would be possible to get a param string name (variable name) used in the ...
0
votes
1
answer
57
views
Why can if statement works using an object (like Map) with ".has()" and no working with ".includes"? [closed]
That's my code to explain my idea better (I'm a non english speaker):
The ".includes()" method doesn't work in this case
...
1
vote
0
answers
59
views
In Django are updates of dict within a form class from a view persistent for all users? [duplicate]
I use Django 5.1.2
In order to clarify what my users need to do when my app serves them a form, I've added a dict to my forms called 'contents'. It contains a bunch of instructions for the template ...