Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I have two questions concerning what Visual Studio adds when you make a GUI project

I have two questions concerning what Visual Studio adds when you make a GUI project

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studio
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12941702
    wrote on last edited by
    #1

    If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window: namespace Welcome Program Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI? And my second question is about this line: Public Partial Class MainWindow:Window All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?

    D B OriginalGriffO L 4 Replies Last reply
    0
    • U User 12941702

      If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window: namespace Welcome Program Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI? And my second question is about this line: Public Partial Class MainWindow:Window All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      All of your code goes into classes. Classes ALWAYS go into a namespace. You cannot have a class without it being in a namespace, even in a console app. MainWindow is the name of your class. The ": Window" part means the class inherits from a class called "Window".

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • U User 12941702

        If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window: namespace Welcome Program Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI? And my second question is about this line: Public Partial Class MainWindow:Window All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        'NameSpaces [^] control semantic scope: the context in which specific names (Classes, Methods, Fields, Properties, etc.) have meaning. They are a tool you can use to organize your code, and, when using different libraries that have duplicate names, to ensure isolation of one meaning from another (prevent name clashes). Going a little "deeper:" we can view NameSpaces as an abstraction of an underlying code base that involves Assemblies; see this to explore this further: [^] C# allows multiple NameSpaces in one file; other languages (ex. Java) do not. It is very typical to use 3rd. party tools, or code libraries (dll's), and typical that you need to import code which will have their own NameSpaces. In C# Visual Studio you do this from the Solution/Project/References/Add Reference menu in the Solution Explorer. Then, you enable the imported code to become available by adding a 'using statement with the name of the NameSpace.

        Member 12974235 wrote:

        Public Partial Class MainWindow:Window

        This is the default declaration of a newly created WPF app.

        Quote:

        _ Partial Class Form1 Inherits System.Windows.Forms.Form

        This what the Designer.vb file in a VB app uses.

        Quote:

        public partial class Form1

        C# declaration.

        «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

        1 Reply Last reply
        0
        • U User 12941702

          If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window: namespace Welcome Program Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI? And my second question is about this line: Public Partial Class MainWindow:Window All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Namespaces: Dave and Bill have covered that comprehensively.

          public partial class MainWindow:Window

          (Note that I corrected your typecase: C# is case sensitive, and "public", "partial", and class" are keywords, "Public", "Partial", and "Class" are not so you would get compilation errors with your original code). public says that the class can be used inside and outside the containing class or namespace: if I reference your Assembly file once you have built it, I can use your class in my code. partial you know about. MainWindow:Window You are declaring a class: public partial class starts that, and MainWindow gives it a name. Without a name, you couldn't create an instance of the class which means you (pretty much) can't use it at all. The colon character ':' tells the compiler that this class called MainWindow is derived from an existing class - in this case the base class is called Window. This is called inheritance and you will meet this later in your course or book as it is very much fundamental to C# (and in fact to all OOPs languages). For the moment, just think of it as saying "MainWindow is a Window and I need to specify that if anything is going to work" - inheritance is one of three very important class "attributes" that you will need to learn, probably together, and they are all rather too complicated to cover in a little text box like this!

          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          B 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Namespaces: Dave and Bill have covered that comprehensively.

            public partial class MainWindow:Window

            (Note that I corrected your typecase: C# is case sensitive, and "public", "partial", and class" are keywords, "Public", "Partial", and "Class" are not so you would get compilation errors with your original code). public says that the class can be used inside and outside the containing class or namespace: if I reference your Assembly file once you have built it, I can use your class in my code. partial you know about. MainWindow:Window You are declaring a class: public partial class starts that, and MainWindow gives it a name. Without a name, you couldn't create an instance of the class which means you (pretty much) can't use it at all. The colon character ':' tells the compiler that this class called MainWindow is derived from an existing class - in this case the base class is called Window. This is called inheritance and you will meet this later in your course or book as it is very much fundamental to C# (and in fact to all OOPs languages). For the moment, just think of it as saying "MainWindow is a Window and I need to specify that if anything is going to work" - inheritance is one of three very important class "attributes" that you will need to learn, probably together, and they are all rather too complicated to cover in a little text box like this!

            Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            fyi: my students have responded well to the idea of a "library of blueprints," where you check out a Class (or, whatever) blueprint (declaration), and build it (instantiation). using this metaphor, you can describe the internal components (Fields, Properties, etc.) of a Class declaration as a "bill of materials and/or required tools, building skills). mmmm ... what would a language running in .NET be without its own syntax ? a carnival ride with no admission fee ? i'm grateful that the abomination of 'let has not snuck in to C#'s pantry, except in that execrable dialect of LINQ. :omg for that, i'll put up with the Elvis operator (#6), and new weirdness' in pattern matching now marching towards us (#7, #8).

            «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

            OriginalGriffO U 2 Replies Last reply
            0
            • B BillWoodruff

              fyi: my students have responded well to the idea of a "library of blueprints," where you check out a Class (or, whatever) blueprint (declaration), and build it (instantiation). using this metaphor, you can describe the internal components (Fields, Properties, etc.) of a Class declaration as a "bill of materials and/or required tools, building skills). mmmm ... what would a language running in .NET be without its own syntax ? a carnival ride with no admission fee ? i'm grateful that the abomination of 'let has not snuck in to C#'s pantry, except in that execrable dialect of LINQ. :omg for that, i'll put up with the Elvis operator (#6), and new weirdness' in pattern matching now marching towards us (#7, #8).

              «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              APL, I suspect! :laugh:

              Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              B 1 Reply Last reply
              0
              • B BillWoodruff

                fyi: my students have responded well to the idea of a "library of blueprints," where you check out a Class (or, whatever) blueprint (declaration), and build it (instantiation). using this metaphor, you can describe the internal components (Fields, Properties, etc.) of a Class declaration as a "bill of materials and/or required tools, building skills). mmmm ... what would a language running in .NET be without its own syntax ? a carnival ride with no admission fee ? i'm grateful that the abomination of 'let has not snuck in to C#'s pantry, except in that execrable dialect of LINQ. :omg for that, i'll put up with the Elvis operator (#6), and new weirdness' in pattern matching now marching towards us (#7, #8).

                «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                U Offline
                U Offline
                User 12941702
                wrote on last edited by
                #7

                You programmers seem to think and speak in the most peculiar, esoteric terms I've ever heard in my life.

                OriginalGriffO B 2 Replies Last reply
                0
                • U User 12941702

                  You programmers seem to think and speak in the most peculiar, esoteric terms I've ever heard in my life.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  Nah, we actually make sense when you understand the terms - just there is a lot of complexity and a need to be precise about what we are saying so there are a lot of technical terms. Compare that with doctors, where the technical terms are there to make it hard for non-medical staff to understand: "Clavicle" for "Collar bone"; "Sphenopalatine ganglioneuralgia" - "ice cream headache"; "Synchronous diaphragmatic fluttering" - "Hiccups"; "Sternutate" - "Sneeze"; "Borborygmi" - "Tummy rumbles"; "Horripilation" - "Goose bumps"; and so on ... they aren't there to make things any clearer!

                  Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  • U User 12941702

                    You programmers seem to think and speak in the most peculiar, esoteric terms I've ever heard in my life.

                    B Offline
                    B Offline
                    BillWoodruff
                    wrote on last edited by
                    #9

                    Perhaps one day you'll take a course in Computer Science.

                    «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                    1 Reply Last reply
                    0
                    • U User 12941702

                      If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window: namespace Welcome Program Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI? And my second question is about this line: Public Partial Class MainWindow:Window All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Name spaces help to avoid "name collisions" when you start creating "solutions" that have multiple "classes", in multiple "projects". A "console app" can easily wind up becoming something "bigger" where the benefits of name spaces become more obvious. Besides allowing one to "split" a "partial" class across multiple source files, partial classes also allow you to "extend" a 3rd party or "generated" source code (class) file without modifying the original. (e.g. Entity Framework "entity" classes)

                      The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        APL, I suspect! :laugh:

                        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                        B Offline
                        B Offline
                        BillWoodruff
                        wrote on last edited by
                        #11

                        Just the sight of the three letters "APL" gives me an immediate cold chill: I was in the first year of a doctoral program at UC Berkeley (long ago, as in the early '80's), and the required research component for the year ... which was supposed to make us masters of statistical inference, wizards of qualitative social science research, etc. ... was taught by a person who decided we (the doctoral students) should grok all his lectures that he chalkboarded using APL. None of us had any prior programming experience ... remember this is back in punch-card jobs and terminals connected to mainframe days; you had to go over to a building to get your print out. The amount of mental bandwidth I wasted pretending the teaching and the APL was intelligible ! I quit the program at the end of the first year: having stuck it out to prove I was not a "quitter." Interestingly enough, a year later I got deep into Lisp, and assembly language. Perhaps I should thank APL for curing me of an academic career ?

                        «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                        OriginalGriffO 1 Reply Last reply
                        0
                        • B BillWoodruff

                          Just the sight of the three letters "APL" gives me an immediate cold chill: I was in the first year of a doctoral program at UC Berkeley (long ago, as in the early '80's), and the required research component for the year ... which was supposed to make us masters of statistical inference, wizards of qualitative social science research, etc. ... was taught by a person who decided we (the doctoral students) should grok all his lectures that he chalkboarded using APL. None of us had any prior programming experience ... remember this is back in punch-card jobs and terminals connected to mainframe days; you had to go over to a building to get your print out. The amount of mental bandwidth I wasted pretending the teaching and the APL was intelligible ! I quit the program at the end of the first year: having stuck it out to prove I was not a "quitter." Interestingly enough, a year later I got deep into Lisp, and assembly language. Perhaps I should thank APL for curing me of an academic career ?

                          «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #12

                          I know the feeling - I was working for a Terminal manufacturer, just before the advent of the PC and they bought an APL company (they made APL interpreters if I recall correctly). So they wanted a APL terminal, which meant I had to sit down with these guys and work out what they actually needed. Took forever to get it all up and running on a Z80 (with 8K RAM and 32K ROM) but it worked pretty well, I think. Don't think we actually sold any, or at least I never got a single bug report ... :laugh:

                          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups