Create a class named 'Student' with a string variable 'name' and an integer variable 'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an object of the class Student. (For C sharp)
using System;
namespace class_student
{
class Program
{
public class Student
{
public string name;
public int roll_no;
}
public static void Main(string[] args)
{
Student stud = new Student();
stud.roll_no = 2;
stud.name = "John";
Console.WriteLine("roll_no: {0}", stud.roll_no);
Console.WriteLine("name: {0}\n", stud.name);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment