title: how to access method in nested class from main - C#
body: <p>this is editing of my first question:
  so i checked the assignment again.
  all code is working as my professor want it to work, but only my question that i asked before is my problem. - how can i execute the method ShowGrade directly from the list (which is course) like:  list[1].ShowGrade(0) without using list[1].s.ShowGrade(0) ??
  i will put here all my code.
  the two console lines in the Main is what he want (and how he wants it), my constraints for the assignment were:
  1. nested class Student in class Course (one student for course).
  2. no constructors at all but the default constructors.
  3. the ShowGrade method won't be in the Course class.
  4. no operator . (dot) in ShowGrade, only []
  5. in method Q1 will be only one query.</p>
  
  <p>so my code is:</p>
  
  <p>course. cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace HW_1
  {
      public class Course 
      {
          private delegate int Del(Course c);
  
          internal string courseName { get; set; }
  
          public  class Student
          {
              internal string stuName { get; set; }
              internal List&lt;int&gt; gradesList { get; set; }
  
              //internal int ShowGrade(int index)
              //{
              //    return gradesList[index];
              //}
          }
  
          internal Student s = new Student();
  
          public override string ToString()
          {
              string gr = null;
              foreach (var g in s.gradesList)
                  gr += g + " ";
              return string.Format("{0, -6} {1, -14} {2, -10}", courseName, s.stuName, gr);
          }
  
      }
  }
  </code></pre>
  
  <p>Program.cs :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace HW_1
  {
      class Program
      {
          private delegate bool Del(Course c);
  
          static void Main(string[] args)
          {
              List&lt;Course&gt; list = new List&lt;Course&gt;
              { 
                  new Course {courseName = "C#", s = new Course.Student {stuName = "Jojo", gradesList = new List&lt;int&gt;(){10, 20, 100}}},
                  new Course {courseName = "C", s = new Course.Student {stuName = "Bambi", gradesList = new List&lt;int&gt;(){99}}},
                  new Course {courseName = "Java", s = new Course.Student {stuName = "Bambi", gradesList = new List&lt;int&gt;(){}}}
  
              };
  
              Console.WriteLine("List of courses:");
              Print(list);
  
              Console.WriteLine("");
              Console.WriteLine("");
              Console.WriteLine("Press P / p for students who passed in average 60 and those who didn't.");
              Console.WriteLine("");
              Console.WriteLine("Press # for C# courses and others.");
              Console.WriteLine("");
              Console.WriteLine("Press any other key for courses with student who have at least one grade of 100 and all oter courses.");
  
              char ch = (char)Console.Read();
              Del d = ((ch == 'P' || ch == 'p') ? (Del)(c =&gt; c.s.gradesList.Count &gt; 0 &amp;&amp; c.s.gradesList.Average() &gt;= 60) : ((ch == '#') ? (Del)(c =&gt; c.courseName == "C#") : (Del)(c =&gt; c.s.gradesList.Contains(100))));
  
              var x = Q1 &lt;IGrouping&lt;bool, Course&gt;&gt;(list, d);
              Print(x);
  
              Console.WriteLine("");
              //Console.WriteLine(list[1].ShowGrade(0));
              //Console.WriteLine(list[2].ShowGrade(3));
  
          }
  
          static IEnumerable&lt;T&gt; Q1&lt;T&gt;(IEnumerable&lt;Course&gt; list, Del d)
          {
              var query =
                  from c in list
                  orderby d(c)
                  group c by d(c) into g
                  select g;
  
              return (IEnumerable&lt;T&gt;)query;
          }
  
          static void Print(IEnumerable&lt;IGrouping&lt;bool, Course&gt;&gt; list)
          {
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Q1 Results:");
              foreach (var g in list)
              {
                  Console.WriteLine();
                  Console.WriteLine(g.Key);
                  Console.WriteLine("---------------");
                  foreach (var c in g)
                      Console.WriteLine(c);
              }
          }
  
          static void Print&lt;T&gt;(IEnumerable&lt;T&gt; list)
          {
              foreach (var l in list)
                  Console.WriteLine(l);
          }
  
  
  
      }
  }
  </code></pre>
  
  <p>the output for the two Console.writeline has to be:</p>
  
  <pre><code>list[1].ShowGrade(0)
  99
  list[2].ShowGrade(3)
  </code></pre>