Home > DeveloperSection > Interviews > Can we make a program having structure or class under structure?

Posted on    September-17-2016 7:01 AM

 C# C#  .NET  Class  Struct 
Ratings:
 1 Answer(s)
  67  View(s)
Rate this:

Abhishek Srivasatava
Abhishek Srivasatava

Total Post:70

Points:350
Posted on    September-17-2016 7:01 AM

Yes, we can make a program having structure or class under structure.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication14
{
    struct demo
    {
    
        public void fun1()
        {
            demo2 d2 = new demo2();
            demo3 d3 = new demo3();
      
            d2.fun2();
            Console.WriteLine("structure under structure is implemented successfully");
            d3.fun2();
            Console.WriteLine("structure under class  is implemented successfully");
        }
        struct demo2
        {
            public void fun2()
            {
                Console.WriteLine("Testing Comment");
            }
        }
        class demo3
        {
            public void fun2()
            {
                Console.WriteLine("Testing Comment");
            }
        }
       
      
    }
    class Program     {
 
        static void Main(string[] args)
        {
            demo d1 = new demo();
            d1.fun1();
            demo2 d2 = new demo2();
            demo3 d3 = new demo3();
 
            d2.fun2();
            Console.WriteLine("Class under structure is implemented successfully");
            d3.fun2();
            Console.WriteLine("Class under class is implemented successfully");
 
            Console.ReadLine();
           
        }
        struct demo2
        {
            public void fun2()
            {
                Console.WriteLine("Testing Comment");
            }
        }
        class demo3
        {
            public void fun2()
            {
                Console.WriteLine("Testing Comment");
            }
        }
       
    }
}

Don't want to miss updates? Please click the below button!

Follow MindStick