Home » Aptitude Questions and Answers » C# Aptitude Questions and Answers

C# Structures Aptitude Questions and Answers | Set 5

C# Structures Aptitude Questions | Set 5: This section contains aptitude questions and answers on C# Structures.
Submitted by Nidhi, on April 10, 2020

1) What is the output of given code snippets?
using System;

struct sample
{
    int a;
    int b;

    public sample(int X, int Y)
    {
        a = X;
        b = Y;
    }

    public void disp()
    {
        Console.WriteLine(a + " " + b);
    }
}

class Employee
{
    static void Main(string[] args)
    {

        sample []S = new sample[2];
        
        S[0] = new sample(10,20);
        S[1] = new sample(30,40);
        
        S[1].disp();
    }
}
  1. 10 20 30 40
  2. 10 20
  3. Syntax Error
  4. 30 40

2) What is the output of given code snippets?
using System;

struct sample
{
    const int a=5;
    int b;

    public sample(int Y)
    {
        b = Y;
    }

    public void disp()
    {
        Console.WriteLine(a + " " + b);
    }
}

class Employee
{
    static void Main(string[] args)
    {

        sample S = new sample(10);
        S.disp();
    }
}
  1. 5 10
  2. 5 1o
  3. Syntax Error
  4. Runtime Exception

3) What is the output of given code snippets?
using System;

struct sample
{
    public int a;
    public int b;
}

class Employee
{
    static void Main(string[] args)
    {
        sample S = { 30, 40 };
		
        Console.WriteLine(S.a + " " + S.b);	

    }
}
  1. 30 40
  2. 30
  3. Syntax Error
  4. Runtime Exception

4) What is the output of given code snippets?
using System;

struct sample
{
    public int a=10;
    public int b=20;
}

class Employee
{
    static void Main(string[] args)
    {
        sample S;

        Console.WriteLine(S.a + " " + S.b);
    }
}
  1. 10 20
  2. 1o 2o
  3. Syntax Error
  4. Runtime Exception

5) Can we create a structure within a structure in C#.NET?
  1. Yes
  2. No







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.