C# Array of structure elements or blocks

Program
using System;
namespace ClassRoomSamples
{
    class Demo13ArrayOfStructureElements
    {
        struct trainee
        {
            public string traineeName;
            public int score;
            public string result;
        };

        static void Main(string[] args)
        {
            //Like int[] a = new int[5];

            //Array of Structure variables
            trainee[] t = new trainee[5];

            Console.WriteLine("How many Records?");
            int count = int.Parse(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Enter Name, score of participants");
                t[i].traineeName = Console.ReadLine();
                t[i].score = int.Parse(Console.ReadLine());

                if (t[i].score >= 7)
                    t[i].result = "Selected";
                else
                    t[i].result = "Not Selected";
            }

            Console.WriteLine("=====================================");
            Console.WriteLine("Name\tScore\tResult");
            Console.WriteLine("=====================================");
            for (int i = 0; i < count; i++)
            {
                Console.Write(t[i].traineeName + "\t");
                Console.Write(t[i].score + "\t");
                Console.WriteLine(t[i].result);
            }

            Console.ReadKey();
        }
    }
}

Output

How many Records?
3
Enter Name, score of participants
Subanila
8
Enter Name, score of participants
Mathusudhani
7
Enter Name, score of participants
Chitra
5

=====================================
Name         Score      Result
=====================================
Subanila        8       Selected
Mathusudhani    7       Selected
Chitra          5       Not Selected

2 comments:

  1. ASP.NET Core Web API is a modern framework developed by Microsoft for building fast, secure, and scalable web APIs. It enables developers to create RESTful services that allow web applications, mobile applications, and other software systems to communicate with backend services using HTTP methods such as GET, POST, PUT, and DELETE. It supports C# and integrates with the .NET ecosystem for efficient application development.

    ReplyDelete
  2. ASP.NET Core Web API is widely used for developing business applications, e-commerce platforms, mobile app backends, cloud services, and microservices. Dot Net Full Stack Developer Course
    Developers can work with features such as routing, middleware, dependency injection, authentication, authorization, data validation, and database connectivity. Learning ASP.NET Core Web API helps developers build reliable and maintainable backend services for modern applications.

    ReplyDelete