Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication7
{
class Program
{
#region//Main() Put everything thats finished in here to output it to Console Apllication.
static void Main(string[] args)
{
FirstPart();
}
#endregion
#region
static void FirstPart() // don't know what else to call this.
{
//Console.WriteLine(numS());// commented out
This is where my question lies.
string pi = Console.ReadLine();
PItoArray = pi.ToCharArray(pi.Min(),pi.Max());
Console.WriteLine(PItoArray);
End of where my question lies.
}
#endregion
#region //numS() gets number of char in player input.
//static int numS()
//{
// int num = PlayerInput().Length;
// return num;
//}
#endregion
#region//PlayerInput() Gets whatever player writes in console apllication
static string PlayerInput()
{
string S = Console.ReadLine();
return S;
}
#endregion
static char[] PItoArray;
}
}
Now these are the details (If you need more please feel free to reply as such.):
i tried to use num.max instead of pi.max, my personal preference to split everything up, but with both cases I get an out of range exception where the index is either negative or greater than the collection the way i'm thinking it should work is that it
sets whatever i write, to pi variable
then splits each char into char array
then uses pi to determine what is min and max.
then it should write it out exactly the way it was written. ex. ""hello" input Turns into "hello" output.
Now Here's the 3 questions I have:
Is my logic correct? If not please excuse me i'm 18 and mainly i like to explore what i can and can't do.
How do I use char array's min and max value ex. If i write Hello i can use
char[] Var = pi.ToCharArray(0,5);
ConsoleWriteLine(Var);
The output would be "Hello" Right? but what if i wrote "Hello World" how would i get all of the char's in a string no matter the amount of char's in said string, or a better way of asking is how do i use the amount of char's in a string to get a min & max value to the ToCharArray(min,max) so if I wrote a 10 letter sentence or a 100 letter sentence I would never get a out of range exception?
- Is there a way to do this in a simple 1-5 line code? I'm not lazy but easier is easier so why not use it.