Thursday, 5 December 2013

Using structures instead of class

Providing you the same output but with structure instead of classes or method in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace strct_program1
{
    struct stud_details
    {
       public string name, course;
       public int sid, regid;
    };
    public class Program
    {
        
        public static void Main(string[] args)
        {
            stud_details sd = new stud_details();
            Console.WriteLine("Enter the details of student");
            Console.Write("Enter the name ");
            sd.name = Console.ReadLine();
            Console.Write("Enter the course ");
            sd.course = Console.ReadLine();
            Console.Write("Enter the StudentID ");
            sd.sid = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter the RegistrationID ");
            sd.regid = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("\n\n\nStudent Details");
            Console.WriteLine("Name " + sd.name);
            Console.WriteLine("Course " + sd.course);
            Console.WriteLine("studentID " + sd.sid);
            Console.WriteLine("RegistrationID " + sd.regid);
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment