|
-
Dec 18th, 2009, 01:17 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] class members
if i have an enum that is declared within a class, is the enum considered a member of the class, or does it just borrow the namespace of the class?
if i have a delegate that is declared within a class, is the delegate considered a member of the class, or does it just borrow the namespace of the class?
Last edited by pacerier; Jan 7th, 2010 at 04:08 PM.
-
Dec 18th, 2009, 01:22 AM
#2
Re: class members
Anything declared within a type is a member of that type, although a nested type is a little different to other members. If one type is nested inside another type then the outer type acts as a namespace, and types are members of their namespaces.
-
Dec 18th, 2009, 02:00 AM
#3
Thread Starter
Hyperactive Member
Re: class members
if i create a class library called Lib, and within Lib there is a class ClassA, what is the relation of ClassA to Lib?
and what exactly is Lib? is it just a namespace existing for the sake of holding classes?
is my class library Lib contained within anything? like is it under System, or is Lib at the highest lvl already?
EDIT
q1. must all libraries be a namespace?
q2. are System, System.Core, System.Data/Drawing/Windows/Xml all namespaces?
q3. is System.Core a Library? or is it a Namespace declared within System Library?
q4. so all namespaces must be either a library or a class, is that right to say
q5. and all classes have a namespace?
q6. is it rite to say that members of a namespace must be one of these: variables/Classes/Methods/Properties/Enums/Delegates/Events/Namespaces
q8. can a library contain a library?
Last edited by pacerier; Dec 18th, 2009 at 02:46 AM.
-
Dec 18th, 2009, 03:06 AM
#4
Re: class members
Libraries and namespaces have no specific relationship. A class library is a DLL. DLLs are executable files, just like EXE files, but they have no entry point so they cannot be executed directly. They must be referenced by an EXE or another DLL. Libraries are physical units of types: each DLL physically contains one or more type declarations.
A namespace is a logical unit of types: each namespace has one or more member types but the namespace doesn't physically exist anywhere. Think of libraries as houses, where types physically live, and namespaces as families that just create logical groupings.
Namespaces are used to group related types but, as the name suggests, their reason for existence relates to names. Within each namespace, every name must be unique. This allows you to give two or more types the same name but they are different types because they are in different namespaces.
When you create a project, by default both the assembly name and the root namespace will be the same as the project name. You are free to change either or both though, plus you can declare child namespaces under the root. Generally speaking, a well designed app will have some correspondence between assembly names and namespaces but it is not required. Note also that one assembly can contain members of more than one namespace, plus multiple members of the one namespace can be declared in different assemblies.
-
Dec 18th, 2009, 03:48 AM
#5
Thread Starter
Hyperactive Member
Re: class members
ic, so the Core of System.Core really is a child namespace of System Namespace rite, btw what do you mean when you say the "assembly", is it a physical or logical type and what does that refer to?
-
Dec 18th, 2009, 04:24 AM
#6
Re: class members
An assembly is a .NET executable, i.e. EXE or DLL file.
-
Dec 18th, 2009, 04:41 AM
#7
Thread Starter
Hyperactive Member
Re: class members
do other languages (perl/java/python/ruby/c etc) uses DLL as well?
-
Dec 18th, 2009, 05:20 AM
#8
Re: class members
DLLs go way back. They've been used in Windows and I guess even DOS for a long time. Any language that compiles on the Windows platform would be able to create DLLs. Scripting languages don't get compiled so they don't create DLLs.
It's also worth noting that .NET DLLs are not the same as standard Windows DLLs. A DLL is is an executable, so it contains machine code. A .NET DLL contains a machine code header, which allows it to be executed on Windows, but that header redirects to the .NET Framework for execution of the MSIL code that makes up the bulk of the file.
-
Jan 5th, 2010, 02:05 PM
#9
Thread Starter
Hyperactive Member
Re: class members
 Originally Posted by jmcilhinney
Anything declared within a type is a member of that type, although a nested type is a little different to other members. If one type is nested inside another type then the outer type acts as a namespace, and types are members of their namespaces.
sry just to clarify, a nested type is either a Enum or Delegate or Structure or Class and there is nothing else other than this 4?
-
Jan 5th, 2010, 02:10 PM
#10
Re: class members
I wouldnt class an Enum or a Delegate as a "Type" myself, just Structures and Classes - although I'm not 100% sure about the Enum, as its essentially just a nice way of looking at Integers, but I guess it might officially be classes as a Type.
EDIT: Just done a bit of research and it looks like I was wrong and Enum and Delegate are officially Types 
As for your actual question as to whether there are any others, the only other that I can think of that might qualify is an Interface but perhaps someone else can confirm whether or not that would be classed as a Type?
Last edited by chris128; Jan 5th, 2010 at 02:18 PM.
-
Jan 5th, 2010, 08:30 PM
#11
Re: class members
 Originally Posted by chris128
I wouldnt class an Enum or a Delegate as a "Type" myself, just Structures and Classes - although I'm not 100% sure about the Enum, as its essentially just a nice way of looking at Integers, but I guess it might officially be classes as a Type.
EDIT: Just done a bit of research and it looks like I was wrong and Enum and Delegate are officially Types
As for your actual question as to whether there are any others, the only other that I can think of that might qualify is an Interface but perhaps someone else can confirm whether or not that would be classed as a Type?
If you can do this:then XYZ is a type. That means that classes, structures, interfaces, delegates and enumerations are all types. Think about what a "type" is in the real world. You might say "what type of car do you have". A "type" is essentially a template for a group of objects that are basically the same, in the real world and in programming.
A nested type is simply a type that's declared inside another type. A class is a class, no matter what. If one class is declared inside another class then they are both classes. The one that's declared inside the other is called a nested class just to indicated that it's declared within another class, but it really has no special properties or limitiations as a result. The only difference between a nested type and a non-nested type is that nested types can be declared Private in order to limit their scope to the type that they're nested within. Other types cannot be declared Private because Private specifically means that the declared entity's scope is limited to the type it's declared within. If a type is not declared within another type then its scope obviously can't be limited that way, so Private is not valid.
Last edited by jmcilhinney; Jan 5th, 2010 at 08:35 PM.
-
Jan 5th, 2010, 08:54 PM
#12
Thread Starter
Hyperactive Member
Re: class members
ok thx that does clear things up = )
-
Jan 7th, 2010, 08:29 AM
#13
Thread Starter
Hyperactive Member
Re: [RESOLVED] class members
sry another small question, can i firmly tell someone that any types (class/enum/delegates/structure/interface) declared within MyClass scope, is strictly not a member of MyClass, but they are only declared under MyClass namespace.
-------
anyway how do we unmark threads that are resolved to unresolved?
-
Jan 7th, 2010, 09:28 AM
#14
Re: [RESOLVED] class members
anyway how do we unmark threads that are resolved to unresolved?
Go to your first post in this thread and click the Edit button, then click the Go Advanced button. Then you will see your original post but above that there will be a Subject or Title box with "[RESOLVED] Thread_Name_Here" in it - just delete the RESOLVED part and submit the post
-
Jan 7th, 2010, 01:40 PM
#15
Thread Starter
Hyperactive Member
Re: class members
hmm i cant seem to get rid of the small tick beside it, any tips?
-
Jan 7th, 2010, 02:00 PM
#16
Re: class members
Do the same thing again but look just below the textbox that shows the contents of your post and you should see a section called Post Icons and the Tick icon will be selected - set it back to No Icon.
-
Jan 7th, 2010, 04:20 PM
#17
Thread Starter
Hyperactive Member
-
Jan 8th, 2010, 03:48 AM
#18
Re: [RESOLVED] class members
 Originally Posted by pacerier
sry another small question, can i firmly tell someone that any types (class/enum/delegates/structure/interface) declared within MyClass scope, is strictly not a member of MyClass, but they are only declared under MyClass namespace.
No, you can't say that at all. Anything declared within a type is a member of that type, and classes are not namespaces.
-
Jan 9th, 2010, 06:51 AM
#19
Thread Starter
Hyperactive Member
Re: class members
ook thx for the clarification
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|