PrepAway - Latest Free Exam Questions & Answers

6 Comments on “What is the value of _number after the code is executed?

  1. Ivica says:

    Hi,
    I tried code above:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace _010_Class_Number
    {
    class Program
    {
    static void Main(string[] args)
    {
    ANumber mynumber = new ANumber(3);
    Console.WriteLine(mynumber);
    Console.ReadLine();
    }
    public class ANumber
    {
    private int _number = 7;
    public ANumber()
    {
    }
    public ANumber(int number)
    {
    _number = number;
    }
    //public static implicit operator int(ANumber a)
    //{
    // return a._number;
    //}
    }
    }
    }

    Output: _010_Class_Number.Program+ANumber
    And when I add implicit operator it works!
    Am I doing something wrong?

    Thanks!




    0



    0

Leave a Reply