Accessing a value in a method using *
It means "take and discard any number of parameters".
Both definitions are technically the same, but not giving a name to the argument array means you can't access it.
accessing the return value of a method in java
First, to get you going, positiveList.indexOf(positiveList.get(i));
returns i
, think about what you do here.
What you obviously want is a list of arrays that fulfill a certain condition for a given list. Therefore, returning only a single int index
is not the solution. Try to return a list of all indices, like in this example:
private static ArrayList<Integer> getIndex(List<Double> positiveList, double nvalues) {
ArrayList<Integer> indices = new ArrayList<Integer>(); //something like this
for(int i = 0; i < positiveList.size(); i++){
if(positiveList.get(i)<=nvalues){
indices.append(i); //add an index to the list
}
}
return indices;
}
With this list, you can do whatever you want in your main method now.
Accessing value of object/instance of a class, made by using method from another class
You should create a class. Something like this:
public class Character
{
private readonly string[] nameList = new string[]
{
"John",
"Jack",
"Josh",
};
public string Name { get; private set; }
public Character()
{
Random randomGenerator = new Random();
Name = nameList[randomGenerator.Next(0, nameList.Length - 1)];
}
}
In Main class instantiate a Character type and you can reach the object name with getter.
Accessing the value of a private variable in a method and making it global
var token;//now it is global, outside any class it the file
class _HomeState extends State<Home> {
return Scaffold(
//...
);
}
_oauth2() {
setState(() {
authenticate(values);
});
}
authenticate(...) async {
login code
token = tokenValue;//set the value here
return tokenValue;
}
}
Referencing a variable from another method
Usually you'd pass it as an argument, like so:
void Method1()
{
var myString = "help";
Method2(myString);
}
void Method2(string aString)
{
var myString = "I need ";
var anotherString = myString + aString;
}
However, the methods in your example are event listeners. You generally don't call them directly. (I suppose you can, but I've never found an instance where one should.) So in this particular case it would be more prudent to store the value in a common location within the class for the two methods to use. Something like this:
string StringA { get; set; }
public void button1_Click(object sender, EventArgs e)
{
StringA = "help";
}
public void button2_Click(object sender, EventArgs e)
{
string b = "I need ";
string c = b + StringA;
}
Note, however, that this will behave very differently in ASP.NET. So if that's what you're using then you'll probably want to take it a step further. The reason it behaves differently is because the server-side is "stateless." So each button click coming from the client is going to result in an entirely new instance of the class. So having set that class-level member in the first button click event handler won't be reflected when using it in the second button click event handler.
In that case, you'll want to look into persisting state within a web application. Options include:
- Page Values (hidden fields, for example)
- Cookies
- Session Variables
- Application Variables
- A Database
- A Server-Side File
- Some other means of persisting data on the server side, etc.
How to access an object in another method in C#?
Inside your class Game
create a private Player user
variable and instantiate inside your Setup()
function.
Example how it would look:
class Game{
private Player user;
public void Setup(){
user = new Player();
}
}
then you have access to user.score
inside the whole Game class
Related Topics
Why Should You Avoid the Then Keyword in Ruby
Empty Strings at the Beginning and End of Split
Rails Syntax Error: Unexpected Keyword_Ensure, Expecting Keyword_End
Why Do I Get "Undefined Method 'Paginate'" Error in Production
Wicked_Pdf Is Not Rendering Header
How to HTML_Escape Text Data in a Sinatra App
Ruby Range: Operators in Case Statement
Can Anyone Explain This Array Declaration to Me
Ruby Regexp to Replace Equations
Ruby: Difference Between Read_Timeout and Open_Timeout
How to Get the Nth Element of an Enumerable in Ruby
Openssl Causing Very Slow Rails Boot Time on Windows
Error Requiring Pg Under Rvm with Postgres.App
How to Create Two Routes in One Block in Grape
Installing Ruby Using Rvm Fails, Without Trace