Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello.

I have a variable of type string.This variable holds a string value.
If 0 is 0,
2 is numbered 0,1 lines. So if the student variable is different from 0 I would like to print this value.
I want to print the Students variable (if it is different from 0)
For example ; I want to print if the numbers are worth the following way.

[0] Paul string
[1] Christina string

Console.WriteLine ("studentnames", students);

I want to print: effected Alex, Mary

How do I print this way?

What I have tried:

public List<string> students=new List<string>();
Posted
Updated 2-Mar-19 22:06pm
v4
Comments
OriginalGriff 2-Mar-19 16:33pm    
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
[no name] 2-Mar-19 17:11pm    
Hello.
First of all, thank you for your help.
I'm making examples to improve myself, and I'm hanging around.
Actually, what I want is easy, but I can't do anything.
I'm keeping a list as a string. And I wonder how the string value is printed.
If I look at the list with foreach, I can't print it like this.
Console.WriteLine ("", students);

If I want;

if (studentcount! = 0)
{
Console.WriteLine ("studentnames", students);
}

I wrote it if I didn't.I wonder how I can solve this.Thanks for your help.

1 solution

I am not sure if i understood your problem completely, but still proposing a solution based on my understanding. I think you need to try something like this:

C#
for(var i= 0; i < students.Count; i++)
{
    Console.WriteLine("[" + i.ToString() + "] " + students[i] + Environment.Newline);
}
 
Share this answer
 
Comments
[no name] 3-Mar-19 4:37am    
First of all thank you very much.I hadn't tried using the for loop.I will try this solution.Thank you 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