Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.I'm easy but I have a question for not knowing.First of all, I'm sorry to ask you so easily.cs. in my hand.I have a list as a list.This value is less than 10 in the case of numbers as the list holds.I want to print this value in another class. How can I print it.


Numbers.cs

public List<string> numberlist=new List<string>



CalculateProcess.cs

//In this class I want to print the value in this list.How do I print.

What I have tried:

Numbers.cs
public List<string> numberlist=new List<string>


CalculateProcess.cs

// try code.
Console.Writeline(numberlist);  or  NumberFiles.Send(path,number,numberlist,"success");
Posted
Updated 27-Feb-19 10:43am

Check my past answer: How do I call list in another class?[^]
 
Share this answer
 
Comments
[no name] 27-Feb-19 15:39pm    
Hello.I'm doing the same in-class methods. I want to call another class and print it.
Thank you for your help.
It's not really complicated, but it can seem so. What you need is to use the instance of the numbers class to access the list.
And that probably doesn't mean anything, but it's something you do every day and don't even think about.

So ... lets ignore it, and think about a car. Suppose you put your mobile in the glove box of your car - and then trade it in on a new one. If you open the glove box, do you expect your mobile to be there? Of course not! They are both "your car", but the actual instance of a vehicle has changed. And you know that: "your car" is different from "my car", "his car", "her car". And a single car may be accessed by several names: "your car", "this car", "that car" - the all refer to the same vehicle.
In order to drive to the shops, you need to have the right instance of a car: "your car" rather than "my car".

And classes are the same: in order to use elements of a class you need to specify which instance of the class you are talking about. Inside the class definition that's easy: you have this (Explicitly or implicitly) which says "the current instance" whichever one it is.
But outside the class it's more complicated: you have to find the instance, and refer to it:
C#
Car myCar = new Car("Mercedes", "A-class", Color.Black);
...
myCar.Engine.Start();</pre
<pre lang="c#">Car yourCar = new Car("Ford", "Fiesta", Color.Red);
...
yourCar.GLoveBox.Add(yourMobile);


So to access your list, you just need to supply the instance (via a variable) and specify the collection.

The other way is to make the list static, and access it via the class name - but in that case there is only one list for all instances of the class (if you like, a static glove box would have a wormhole in it which meant the same glove box would be accessed from all cars - not practical in the real world, and probably not what you want in your app!)
 
Share this answer
 
Comments
[no name] 27-Feb-19 16:49pm    
Thank you very much for your explanation. I think I understood and understood something like this.
Is it true?

Calculate OldList=new Calculate();


CalculateProcess NewList=new CalculateProcess();
NewList.Add(OldList);
OriginalGriff 28-Feb-19 3:30am    
Probably not, unless your CalculateProcess class contains a method called "Add", or is derived from a collection class such as a list.
Your Numbers class contains a list - why do you not use that?

Perhaps it would help if you explained what you are trying to achieve here (rather than the details of your solution) so we both understand better what you need to do?
[no name] 28-Feb-19 4:41am    
Thank you.My purpose is to print the list.
OriginalGriff 28-Feb-19 4:51am    
:sigh:
Remember, we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

So we don't know "what list", "what instance", what your classes are meant for, what they contain or should contain, what the rest of your code is supposed to do, or anything at all unless you explicitly tell us! Stop trying to type as little as possible - it doesn't help anyone ...
[no name] 28-Feb-19 11:28am    
I'm sorry, I'm making you.
There are methods that do database insert select operations in the first class. public void MNumbers () {// insert database. }

Calculate process class is I want to print the value of the list in the first class. I want to print the value of the field. How do I call.

How do I get the list value in the second class because the list already gets its value.
Thank you very much for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900