An online shopping website has the requirement of updating specific product prices during festive seasons.The developer has written the following code.

When the tester ran the code, he found out that product price was not updated.

What was the error?

   public struct Product 
   {
        public int productId;
        public string productName;
        public int price;
    }
   
   public class Program 
   {
        public static void Main()
   	    {
            Product productObj = new Product();
            productObj.productId = 101;
            productObj.productName = "XBOX One";
            productObj.price = 40000;
            Console.WriteLine("Before Price Update : " + productObj.price);
            UpdatePrice(productObj);
            Console.WriteLine("After Price Update : " + productObj.price);
        }
   	    
        public static void UpdatePrice(Product productObj)
        {
            productObj.price = 35000;
        }
   }

The method “UpdatePrice()” cannot be called directly

Struct is a value type so the price would not be updated

Struct variable values can be set only once and cannot be changed further

No Error and the code will work fine.

Verified Answer
Correct Option - d

To get all Basic CSharp Programming Assessment Exam questions Join Group https://bit.ly/infy_premium_group

We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.

Qtr No. 213, New Town Yehlanka Indore 454775

admin@prepflix.in