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
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
C is the correct answer
3 is the value after code is executed
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!
chaange by and by
See the output.
sorry, change private int _number = 7; by public int _number = 7; and Console.WriteLine(mynumber); by Console.WriteLine(mynumber._number);
compile error because keyword Class (with big C) does not exist