What is the value of _number after the code is executed?

You create an object of type ANumber. The class is defined as follows.

What is the value of _number after the code is executed?

You create an object of type ANumber. The class is defined as follows.

What is the value of _number after the code is executed?

A.
Null

B.
0

C.
3

D.
7



Leave a Reply 6

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


mandisa

mandisa

C is the correct answer

mandisa

mandisa

3 is the value after code is executed

Ivica

Ivica

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!

eucledio

eucledio

chaange by and by

See the output.

eucledio

eucledio

sorry, change private int _number = 7; by public int _number = 7; and Console.WriteLine(mynumber); by Console.WriteLine(mynumber._number);

ivan

ivan

compile error because keyword Class (with big C) does not exist