Use float[] to console readline C#

Updated on February 5, 2018 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
10 on February 5, 2018

Hi, I was wondering how I can use float[] into console.readline, I need to get the answer from the user to get him to decide which index number he wants to remove from the arraylist. Any ideas? 

 

Console.WriteLine(“Decide wich temperature you want to remove”);

for (int i = 0; i < myList.Count; i++)
{
Console.WriteLine(i + “: ” + myList[i][0]);
}

float[] floatAnswer = float[].TryParse(Console.ReadLine());

myList.Remove(floatAnswer);

  • Liked by
Reply
9 on February 5, 2018

If you’re removing the entire entry from myList, a list of array if I remember correctly, then you could just reference it by its index, I.E. the number the user types in.

int answer = Console.ReadLine();
myList.Remove(myList[answer]);

on February 5, 2018

You mean the square brackets?

 

https://dotnetfiddle.net/7leyOE

on February 5, 2018

I’m sorry, I don’t understand the question.

on February 5, 2018

If you’re removing the entire entry from myList,

do you mean the square brackets? These  [ ]

on February 5, 2018

Yes

on February 5, 2018

And try to skip all the arrays ?

 

on February 5, 2018

Again, sorry, I don’t understand.
The example I gave will remove the entry from myList at the index the user types in.
There is no skipping any arrays.

on February 5, 2018

Okay, got it. 

https://dotnetfiddle.net/UZ0U3F 

Can you see any problem here? 

I don’t get the right result from:

for (int i = 0; i < myList.Count; i++)
{
Console.Clear();
Console.WriteLine(myList[i] / myList.Count);

}

on February 5, 2018

What are you trying to accomplish with this? All this will do is write the last entry into myList over the count. Which I dont think it can do, because you can’t divide a float[] by an int.

 

on February 5, 2018

Experiment a little bit, but I solved it, thanks ^^

Show more replies
  • Liked by
Reply
Cancel