I apologize in advance for dumping (again) so many wordy, incoherent questions; thus, of course, thank you for any help, no matter how little! Google/wikipedia has helped me alot, but for the weirder ones, I need your expertise!º¤ø,¸¸,ø¤º°`°º¤ø,¸
1) Why do private classes require a container or outer class? My guess is that's how they can share its members with other classes.
2) Is it fair to think of an object as an instance of a class, much like a variable instance of a data type? (except that objects can be methods or variables)
3) To paraphrase my textbook:
suppose you had two separate namespaces each with a class of the same name. If the Main() method was in the first namespace and you wanted to use a method or variable in the second namespace,
then the fully qualified name is required.
But whether the class name is same or not, wouldn't you have to do so anyway, in general?
4) Is the protected access level the same as private, except the former can include derived/sub/nested classes? I believe the usual definition is that the private class gives access to itself and other classes in the shared container class... But I'm not too sure about this, since I think you can run at least the Main() in a class nested in the private class (with private variables).
5) Is it common that private classes contain public variables (modifiers) in practice? I wasn't sure since I have read that for properties, it is required that the restrictiveness is the other way around. I also thought it was possible to eliminate the private class itself, leaving the variables and the Main() method in a container if the variables were going to be public.
6) To paraphrase my textbook: "public access level is used with types and members.
Access is not restricted". By type, do they mean data type? (just making sure)
7) I'm still not sure regarding the difference between a break and return, as they both terminate loops? Or in other words, I know break means go to the next statement, but for return, what does "return statement transfers control to the calling method" mean exactly?
8) Not exactly a question, but I just discovered you can use different counter labels (e.g. different letters) for the same array elements (within the same method) when you want to print them. I just thought that was strange.
9) Not exactly a question, but wanted verification of my intepretation of the following program (its actually quite quite straightforward; the program either accepts your new number input, or it keeps its old one and reject yours). Intepretation below.
Code:
class MyClass
{
private int item = 144; //it seems that if you leave out 144, it is 0 by default
public int Number //usually related to item, so pick a name like Item
{
get
{
return item;
}
set
{
if ((value >= 100) && (value <= 1000))
item = value;
else
Console.WriteLine("The value is not within the permitted range!");
}
}
static void Main()
{
// Create an object:
MyClass mc = new MyClass();
// Read a value from the keyboard:
Console.Write("Please enter the new value: ");
int myInt = Int32.Parse(Console.ReadLine()); //you can parse user input
// Assign the value to the property:
mc.Number = myInt;
// Display the value:
//mc.Number declared previously as a property
Console.WriteLine("The current value is: {0}", mc.Number);
Console.ReadLine();
}
}
I belive the compilation is like this, in general: After the object is created, in Main(), mc.Number = myInt sends the user input, myInt, to the property (method) area (i.e. public int Number). Get and return item means we consider or read the initialized item 144, before we let myINt equal keyword value (field?) for the if-else statement. In either case, we exit the property with the retrieved item.
Thank you once again! Cheers!!!!