×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# Structures Aptitude Questions and Answers | Set 4

C# Structures Aptitude Questions | Set 4: 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()
    {
        a = 10;
        b = 20;
    }

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

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

        S.disp();
    }
}
  1. 10 20
  2. 10
  3. Syntax Error
  4. Runtime Exception

2) 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 = new sample();

        S.a = 10;
        S.b = 20;

        Console.WriteLine(S.a + " " + S.b);
    }
}
  1. 10 20
  2. 10
  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)
    {
        const sample S;

        S.a = 10;
        S.b = 20;

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

4) 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;

        S = new sample[2];

        S[0].a = 10;
        S[0].b = 20;
        
        S[1].a = 30;
        S[1].b = 40;

        Console.WriteLine(S[0].a + " " + S[0].b + " " + S[1].a+ " " + S[1].b);
    }
}
  1. 10 20 30 40
  2. 10 20
  3. Syntax Error
  4. Runtime Exception

5) 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]{{10, 20},{30,40}};

        S[0].disp();
    }
}
  1. 10 20 30 40
  2. 10 20
  3. Syntax Error
  4. Runtime Exception



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.