Results 1 to 19 of 19

Thread: [RESOLVED] class members

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: class members

    An assembly is a .NET executable, i.e. EXE or DLL file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: class members

    do other languages (perl/java/python/ruby/c etc) uses DLL as well?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: class members

    Quote Originally Posted by jmcilhinney View Post
    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?

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: class members

    Quote Originally Posted by chris128 View Post
    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:
    vb.net Code:
    1. Dim abc As XYZ
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: class members

    ok thx that does clear things up = )

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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?

  14. #14
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: class members

    hmm i cant seem to get rid of the small tick beside it, any tips?

  16. #16
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: class members

    oo ok thxalot

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] class members

    Quote Originally Posted by pacerier View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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
  •  



Click Here to Expand Forum to Full Width