Concept of Private class in C#

后端 未结 5 1552
忘掉有多难
忘掉有多难 2021-02-01 01:48

Can private classes exist in C#, other than in Inner classes?

5条回答
  •  -上瘾入骨i
    2021-02-01 01:51

    We can declare a class as Private inside other class. kindly find the code below on how to achieve the same:

     public class Class1
      {
        temp _temp ;
        public Class1()
        {
          _temp = new temp();   
        }    
    
        public void SetTempClass(string p_str, int p_Int)
        {
          _temp.setVar(p_str, p_Int);
        }
    
        public string GetTempClassStr()
        {
          return _temp.GetStr();
        }
    
        public int GetTempClassInt()
        {
          return _temp.GetInt();
        }
    
        private class temp
        {
          string str;
          int i;
    
          public void setVar(string p_str, int p_int)
          {
            str = p_str;
            i = p_int;
          }
    
          public string GetStr()
          {
            return str;
          }
    
          public int GetInt()
          {
            return i;
          }
        }
      }
    

提交回复
热议问题