Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ArrayofElements
- {
- class student
- {
- public String rollno;
- public String name;
- public student(String rollno, String name)
- {
- this.rollno = rollno;
- this.name = name;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- student[][] obj = new student[3][];
- for (int i = 0; i < obj.Length; i++)
- {
- obj[i] = new student[3];
- }
- for (int i = 0; i < obj.Length; i++)
- {
- for (int j = 0; j < obj.Length; j++)
- {
- Console.WriteLine("Enter Name : ");
- String arr = Console.ReadLine();
- Console.WriteLine("Enter Roll Number : ");
- String arrr = Console.ReadLine();
- int a = arr.Length;
- obj[i][j] = new student(arrr, arr);
- }
- }
- Console.WriteLine("\n Student Details are : \n");
- for (int i = 0; i < obj.Length; i++)
- {
- for (int j = 0; j < obj.Length; j++)
- {
- Console.WriteLine("Name: {0} Roll No: {1}", obj[i][j].name,obj[i][j].rollno);
- }
- }
- int flag = 0;
- Console.WriteLine("Enter student Roll No. to be searched: ");
- String n = Console.ReadLine();
- for (int i = 0; i < obj.Length; i++)
- {
- for (int j = 0; j < obj.Length; j++)
- {
- if (obj[i][j].rollno == n)
- {
- flag = 0;
- Console.WriteLine("{0}", obj[i][j].name);
- }
- else if(obj[i][j].rollno != n)
- {
- flag = 1;
- }
- }
- }
- if (flag == 1)
- {
- Console.WriteLine("Roll number not found");
- }
- else
- {
- Console.WriteLine("Roll number found");
- }
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment