Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

user input to array object c#

using System;
namespace array_sample
{
    class StudentData
    {
        static void Main(string[] args)
        {
            Regex num = new Regex(@"^d{5}$");
            Student[] ourStudents = new Student[24];   
            // declared an array of stduent objects 

            for (int i = 0; i < 24; i++)
            {
                Console.WriteLine("Enter your Student Number :");
                Match n = num.Match(Console.ReadLine());
                if (n.Value != "")
                {
                  ourStudents[i].Number = Int32.Parse(Console.ReadLine()); 
                  // make sure to convert to integer

                  Console.WriteLine("Enter your Name :");
                  ourStudents[i].Name = Console.ReadLine(); 
                }
                Else
                {
                  Console.WriteLine("Number Can only be 5 digits");
                  if (i > 0)
                     {i = i - 1;}
                  else
                     {i = 0;}
                }

            } // end of input loop

            for(i=0; i<24; i++)
            {
                Console.WriteLine("Number : " + ourStudents[i].Number +'	' + "Name :"
                                  + ourStudents[i].Name);
            }// end of output loop

            Console.ReadLine();
        }
    }// end of class
} // end of namespace
Comment

user input to array object c#

for (int i = 0; i<24; i++) //just user the static array length
{
      myStudents[i].Number = Console.ReadLine();
      myStudents[i].Name = Console.ReadLine();
}
Comment

user input to array object c#

Student[] ourStudents = new Student[24];   // declared an array of stduent objects
Comment

PREVIOUS NEXT
Code Example
Csharp :: triangle 
Csharp :: 2d explosion unity 
Csharp :: c# dapper execute stored procedure with parameters 
Csharp :: symfony debug bar 
Csharp :: c# collection of generic classes 
Csharp :: unity set cursor position 
Csharp :: c# async task constructor 
Csharp :: c# get enum name from value 
Csharp :: C# date type no time 
Csharp :: create app() import vue cli 
Csharp :: unity image button 
Csharp :: How do I call a string inside a different class 
Csharp :: c# null check 
Csharp :: Count Rows of table using Linq 
Csharp :: Go Statement in CSharp 
Csharp :: Code snipet for jump script unity 2d 
Csharp :: deleting an item from a vector c# 
Csharp :: ef6 export update 
Csharp :: how to do division with button C# 
Csharp :: C# Convert range 
Csharp :: F# convert generic.List to list 
Csharp :: mailkit send email c# 
Csharp :: c# entity framework order by array 
Csharp :: lista generica como parametro de un metodo en c# 
Csharp :: How do I remove a String Array from a List in C# 
Csharp :: edit form item from class C# 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: how to remove something in c# 
Csharp :: DataTable GetErrors 
Csharp :: search list for words c# 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =