What will be the output when this code is executed?

You are reviewing a C# program. The program contains the following class:

The program executes the following code as part of the Main method:

What will be the output when this code is executed?
A. 10
B. 20
C. 30
D. 40

microsoft-exams

One thought on “What will be the output when this code is executed?

  1. Answer : 30

    using System;

    class MainClass {
    public static void Main (string[] args) {
    Rectangle r1, r2;
    r1 = new Rectangle{length=10, width=20};
    r2 = r1;
    r2.length = 30;
    Console.WriteLine (r1.length);
    }
    }

    class Rectangle {
    public double length{get; set;}
    public double width{get; set;}
    }

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.