Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ArrayofElements
  7. {
  8. class student
  9. {
  10. public String rollno;
  11. public String name;
  12. public student(String rollno, String name)
  13. {
  14. this.rollno = rollno;
  15. this.name = name;
  16. }
  17. }
  18. class Program
  19. {
  20. static void Main(string[] args)
  21. {
  22. student[][] obj = new student[3][];
  23. for (int i = 0; i < obj.Length; i++)
  24. {
  25. obj[i] = new student[3];
  26.  
  27. }
  28.  
  29. for (int i = 0; i < obj.Length; i++)
  30. {
  31. for (int j = 0; j < obj.Length; j++)
  32. {
  33. Console.WriteLine("Enter Name : ");
  34. String arr = Console.ReadLine();
  35. Console.WriteLine("Enter Roll Number : ");
  36. String arrr = Console.ReadLine();
  37. int a = arr.Length;
  38. obj[i][j] = new student(arrr, arr);
  39. }
  40. }
  41. Console.WriteLine("\n Student Details are : \n");
  42. for (int i = 0; i < obj.Length; i++)
  43. {
  44.  
  45. for (int j = 0; j < obj.Length; j++)
  46. {
  47. Console.WriteLine("Name: {0} Roll No: {1}", obj[i][j].name,obj[i][j].rollno);
  48. }
  49. }
  50. int flag = 0;
  51. Console.WriteLine("Enter student Roll No. to be searched: ");
  52. String n = Console.ReadLine();
  53. for (int i = 0; i < obj.Length; i++)
  54. {
  55. for (int j = 0; j < obj.Length; j++)
  56. {
  57. if (obj[i][j].rollno == n)
  58. {
  59. flag = 0;
  60. Console.WriteLine("{0}", obj[i][j].name);
  61. }
  62. else if(obj[i][j].rollno != n)
  63. {
  64. flag = 1;
  65. }
  66. }
  67. }
  68. if (flag == 1)
  69. {
  70. Console.WriteLine("Roll number not found");
  71. }
  72. else
  73. {
  74. Console.WriteLine("Roll number found");
  75. }
  76. Console.ReadKey();
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment