P
p988
Learning C# is much tougher than I expected...Please help me by answering
the following questions! Thank you in advance!
1. Are all Enumerations type Value type?
2. The line,
RegistryKey Reg = new RegistryKey();
gives the error: "No overload for method 'RegistryKey' takes '0' arguments."
After changing it to:
RegistryKey Reg;
everything OK.
Why?
3. Given a struct:
struct Point
{
public int X;
public int Y;
}
If Point P = new Point;
compiler gives an error: "A new expression requires () or [] after type"
In C++, no difference between "Point P = new Point;" and "Point P = new
Point();"
Guess in C#, have to use: "Point P = new Point();"
Is this a correct understanding?
4. "For example, they (structs) are sealed, which means they cannot be
derived from or have any base class other than System.ValueType, which is
derived from Object."
interface IPoint
{
void SetX (int x);
void SetY (Y);
}
struct sPoint : IPoint
{
...
}
Can a struct, sPoint, be derived from IPoint at all?
If "can", will all instances of sPoint are Value type?
5. Given the code below:
interface IPoint
{
void SetX (int x);
void SetY (Y);
}
class cPoint : IPoint
{
...
}
Are all instances of cPoint Reference type automatically?
6. "Structs cannot declare a default (parameterless) constructor."
Is it legal to write a struct like:
struct Point
{
public Point(int a, int b) { X = a; Y = b; }
int X;
int Y;
}
7. A book says NET Framework Data Types can mean any of the following:
Classes, Structs, Interfaces, Enumerations,Delegates.
Why is the primitive type like int not on the list?
8. Is the following code legal in C#?
int a;
a = 123;
Console.WriteLine(a.ToString())
At least, IntelliSense of VS .NET tells me "a" has no member of "ToString().
Not sure...
9. Since everything in C# is derived from Object, then from what is "CPoint"
derived below?
class CPoint
{
public int X;
}
the following questions! Thank you in advance!
1. Are all Enumerations type Value type?
2. The line,
RegistryKey Reg = new RegistryKey();
gives the error: "No overload for method 'RegistryKey' takes '0' arguments."
After changing it to:
RegistryKey Reg;
everything OK.
Why?
3. Given a struct:
struct Point
{
public int X;
public int Y;
}
If Point P = new Point;
compiler gives an error: "A new expression requires () or [] after type"
In C++, no difference between "Point P = new Point;" and "Point P = new
Point();"
Guess in C#, have to use: "Point P = new Point();"
Is this a correct understanding?
4. "For example, they (structs) are sealed, which means they cannot be
derived from or have any base class other than System.ValueType, which is
derived from Object."
interface IPoint
{
void SetX (int x);
void SetY (Y);
}
struct sPoint : IPoint
{
...
}
Can a struct, sPoint, be derived from IPoint at all?
If "can", will all instances of sPoint are Value type?
5. Given the code below:
interface IPoint
{
void SetX (int x);
void SetY (Y);
}
class cPoint : IPoint
{
...
}
Are all instances of cPoint Reference type automatically?
6. "Structs cannot declare a default (parameterless) constructor."
Is it legal to write a struct like:
struct Point
{
public Point(int a, int b) { X = a; Y = b; }
int X;
int Y;
}
7. A book says NET Framework Data Types can mean any of the following:
Classes, Structs, Interfaces, Enumerations,Delegates.
Why is the primitive type like int not on the list?
8. Is the following code legal in C#?
int a;
a = 123;
Console.WriteLine(a.ToString())
At least, IntelliSense of VS .NET tells me "a" has no member of "ToString().
Not sure...
9. Since everything in C# is derived from Object, then from what is "CPoint"
derived below?
class CPoint
{
public int X;
}