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. My thoughts on C#

My thoughts on C#

Scheduled Pinned Locked Moved C#
designcsharpc++cssdiscussion
74 Posts 13 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.
  • B Brian_TheLion

    Hi Richard. No I'm not blaiming C# at all, all I'm looking for is a way to use this programming language that suits my needs. I think it's because I'm use to older languages that had less rules such as quick basic. As a hobby programmer I want to improve on any programming skills I have so I turned to C# and invested my time in trying to learn this language. I understand it's the type of language that can't be learnt in a couple of weeks and slowly things that did not make sense at first are starting to make more sense now. I'm still trying to find a way of one class changing the variables in another class if that's possible. As for my message about almost all programs requiring a user interface... You have a choice when writing a c# program of a console program that uses a dos window or a program that has buttons that the user can click on. I don't know of any program sold these days that is a console program. Brian

    M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #21

    Brian_TheLion wrote:

    I'm looking for is a way to use this programming language that suits my needs

    And there is another large problem. You are basing you "needs" on a legacy system written in basic and hoping to convert it to a modern language and development style. You should really accept that you are up for a rewrite. Look only at the functionality of the original game NOT the code that does the work in basic. If you are going to use a modern OOP language you will need to understand OOP principles BEFORE you begin trying to design the application.

    Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

    B 1 Reply Last reply
    0
    • D Dave Kreskowiak

      Brian_TheLion wrote:

      You have an inventory class and a get/drop class

      No you wouldn't. You would have an Inventory class with Add, Get, and Drop methods. A class is always a noun. The methods exposed by the class are always verbs that perform operations on that noun. Your Inventory class should never output messages to the console. UI operations have nothing to do with managing the data stored by the Inventory class. This is true for ANY OOP language, including C++ and Java.

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

      B Offline
      B Offline
      Brian_TheLion
      wrote on last edited by
      #22

      Hi Dave. I was thinking of breaking up the code so that all get drop actions was handled by a GetDrop class, are you suggesting that I should have the get and drop procedures in the main() class? Brian

      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, Classes get instantiated into objects; all the objects from a single class have the same behavior. Most often these objects are tangible, real-life objects. They have properties that describe them (Age, Color, Size, etc) and methods that operate on them. In an adventure game you would have one or more Adventurer, lots of Rooms, each Room could have Door objects and Window objects, each Adventurer would have an Inventory, an Inventory would hold InventoryItems which could be Keys and Slippers (deriving from InventoryItem), etc. None of these classes would be named after verbs, a get/drop class makes no sense whatsoever. A Get() or a Drop() method would make lots of sense on InventoryItems. If you want to learn object-oriented programming (OOP) then please study the matter by reading a book on the subject, before you start designing and coding. If you refuse to learn OOP properly then please don't touch any of the languages that are intended for OOP, such as Java or C#. FYI: C++ was launched trying to support OOP while maintaining compatibility with non-OOP practices (as in C). I have never been convinced C++ did the programming world a favor. However I am sure Java and C# do. Except maybe for the latest syntax-sugaring additions to those languages. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        B Offline
        B Offline
        Brian_TheLion
        wrote on last edited by
        #23

        Thanks Luc for your reply. In the adventure there is a test each time the player enters commands so if the player enters get slippers the program would check if there was a test to pass first before the slippers could be picked up. The test class has 10 to 14 variables which are counters, flags, location of object, etc. so there is a lot involved in this text adventure game. I think you are suggesting that I have get and drop methods in the main() class rather than in the GetDrop class, is this would you were meaning? So far apart from the GetDrop class I have classes for Inventory, Look (or examine), Movement, Tests and SaveLoad (which might be separate Save and Load classes. The whole program could be written in the Main() class using procedures but I wanted to try creating classes as I wanted code that is in what I call black boxes away from the main code. Also wanted to try using classes to break up the code and make it easier to modify later on as well as learn about the use of classes. I have been reading books and studying examples on C#. Brian

        L 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Brian_TheLion wrote:

          After learning C# for a while it seems that you need to keep within certain rules to have the program compile.

          True for ANY language, not just C#.

          Brian_TheLion wrote:

          It looks like a case of modifying a program so that it works under C#. There is no global variable allowed so in order to move variables between classes means re-writing the program so it fits within the C# rules.

          It's no the rules of C# so much as it is a strict implementation of Object Oriented Programming, which other languages support, not just C#. "Global variables", in my humble opinion, are a lazy and error prone way of moving data between objects.

          Brian_TheLion wrote:

          the program I have in mind that I want to write has many varables between classes

          You're thinking of data used in more than one class as "global". Well, "global" is just another container, just like a class instance is a container, that can be passed into other class methods.

          Brian_TheLion wrote:

          It also makes the program easier to deal with when changes are made.

          Actually, this isn't true. You have code all over the place that can manipulate "global" variables and debugging problems with that code can be a nightmare because there is no central repository controlling access to those variables.

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

          B Offline
          B Offline
          Brian_TheLion
          wrote on last edited by
          #24

          Hi Dave I wrote: It also makes the program easier to deal with when changes are made. You replied: Actually, this isn't true. You have code all over the place that can manipulate "global" variables and debugging problems with that code can be a nightmare because there is no central repository controlling access to those variables. One of my original reasons for using classes was to put things into what I call 'black boxes'. Once the code was working in the class then I could forget about the class. I send data to the class and it sends me back data. I don't need to know what goes on in the class (black box). It's like turn on a TV and getting a picture. I don't need to know what goes on inside the TV to give me a picture. If I need to make some improvements to the inventory then I only need to deal with the code in the inventory class. Brian

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Brian_TheLion wrote:

            I'm looking for is a way to use this programming language that suits my needs

            And there is another large problem. You are basing you "needs" on a legacy system written in basic and hoping to convert it to a modern language and development style. You should really accept that you are up for a rewrite. Look only at the functionality of the original game NOT the code that does the work in basic. If you are going to use a modern OOP language you will need to understand OOP principles BEFORE you begin trying to design the application.

            Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

            B Offline
            B Offline
            Brian_TheLion
            wrote on last edited by
            #25

            Hi Mycroft. I'm doing my best to try and understand OOP from reading and studying examples. The code that was originally written in BASiC Will be pulled apart and put to geather so that it works under the more modern C# structure, so it is like you say a rewrite. I have a good knowledge of how the code works to do a rewrite. Brian

            M 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Brian_TheLion wrote:

              The original code was written in the BASIC language back in the 1980's

              There's the problem. You're trying to force the old, non-OPP code way of doing things into an OOP world where it just doesn't work. You cannot do a line-for-line conversion. You have to understand what the INTENT of the old code and rewrite using modern techniques. This is will result is radically different code because BASIC is NOT VB.NET, or C#, or Java, or C++. You know that your app needs an inventory. How that's implemented in the new version is going to be done VERY differently from how your existing BASIC code implemented it.

              Brian_TheLion wrote:

              Someone suggested that I should look at instances of classes

              You create instances of classes all the time. Every time you "new up" a class. For example:

              IInventory playerInventory = new InventoryManager();
              

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

              B Offline
              B Offline
              Brian_TheLion
              wrote on last edited by
              #26

              I agree with you Dave as I tried a few years ago to convert the Basic code program into Visual Basic code. I now have a good idea of how the code works so I don't need to copy the original code but will do a rewrite that fits into the structure of C#. It seems that programs like C# make for a better programmer as you don't have the lazy ways of writing code like spaghetti with all its goto commands. The like the structure approach of languages like C#. Maybe the next thing I need to do is to work out all classes I need and what code will be as methods in the main() class. I could write all of the code in the Main() class but in doing so I would gain any experience about using classes and the advanages of using classes. Brian

              1 Reply Last reply
              0
              • B Brian_TheLion

                Thanks Luc for your reply. In the adventure there is a test each time the player enters commands so if the player enters get slippers the program would check if there was a test to pass first before the slippers could be picked up. The test class has 10 to 14 variables which are counters, flags, location of object, etc. so there is a lot involved in this text adventure game. I think you are suggesting that I have get and drop methods in the main() class rather than in the GetDrop class, is this would you were meaning? So far apart from the GetDrop class I have classes for Inventory, Look (or examine), Movement, Tests and SaveLoad (which might be separate Save and Load classes. The whole program could be written in the Main() class using procedures but I wanted to try creating classes as I wanted code that is in what I call black boxes away from the main code. Also wanted to try using classes to break up the code and make it easier to modify later on as well as learn about the use of classes. I have been reading books and studying examples on C#. Brian

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #27

                No! GetDrop is not a noun, it is two verbs, it cannot possibly be a candidate for a class. There is no main() class in my world; besides, class names use TitleCase and no parentheses. If Slippers can be gotten, they need a Get() method. If Keys can be gotten, they need a Get() method. Where are the slippers? where are the keys? does the adventurer know? No. Do all the rooms know? No. The slippers and the keys know where they are, it is information that pertains to them, and to nothing elxe. There should be an Inventory object (or even one per Adventurer), and everything inside such Inventory should derive from InventoryItem, which can hold common properties and/or common methods of gettable objects. An item's location would be an obvious property of InventoryItem; and maybe your complex test belongs there, so you don't have to repeat such test code in every single inventory item's code. Inside InventoryItem class, you probably will have good use for a static List where all items get stored, so you can search them. That is how a Room can figure what is present at any point in time. This was my last technical contribution to this topic. From all you write (and all you apparently don't pick up reading our answers) it is very clear to me you are still missing the basics of OOP. If you don't work on this (shut down your computer and go read one or two OOP books now!) you are wasting your and our time. Books tend to present their subject in a structured way, dealing with way more aspects than you are thinking of right now; random questions in a forum can't match that, they become useful after you acquired the foundation, not before. Good luck. Over and out. :java:

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                B 1 Reply Last reply
                0
                • B Brian_TheLion

                  Hi Dave. I was thinking of breaking up the code so that all get drop actions was handled by a GetDrop class, are you suggesting that I should have the get and drop procedures in the main() class? Brian

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

                  I'm not suggesting anything at all. BUt I am saying you don't need a "GetDrop" class for anything. Again, classes are always nouns, not verbs.

                  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
                  • OriginalGriffO OriginalGriff

                    The problem is that you aren't writing a C# program (German letter): you are trying to translate a VB program (English letter) into C# (German letter) by translating each line of code (using a dictionary)

                    Quote:

                    You have an inventory class and a get/drop class

                    Why? Do you do that in the "real world"? Or do you think "I'm wearing trousers. In this pocket I have a hanky and my small change. In this pocket I have my phone, in this one my wallet. My wallet contains my credit cards, store cards, and bank notes"? In an object oriented design, you would have an abstract Container class (or possibly an IContainer Interface) which had Add, Remove, and List methods - because just like your trousers, they "know" where to put your phone - left pocket; wallet - back pocket; and so on. And if the Trousers class derives from Container and so does the Wallet class, you remove a card from your wallet (and it's gone from your trousers as well) pay for your sandwich, and put it back. The idea is that the object knows how to do things that directly affect it: not that you have global functions that manipulate global objects, or a class of "actions" you can "apply" to objects. Why should an inventory be a global variable? Is there only one in the entire game? Or should "monsters" have one as well so you can "Loot the body"? Think of Oblivion / Skyrim and loads of things have inventories: player, barrels, shops, chests, bags, boxes, bodies, npcs, ... and they are all handled the same way because they aren't globals - they are objects contained in the world. As I said, translating doesn't produce good code - using the original as a specification does, because you then write good code in the target language. It doesn't matter which language pair you pick: blind translation isn't a good idea.

                    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
                    Brian_TheLion
                    wrote on last edited by
                    #29

                    Thanks Griff. I like the way you use examples. The reason why I was thinking of having an inventory class was to keep track of objects that the player picked up, like the trousers that keeps a wallet and other things. If the player drops an object then the object is removed from the player and appears in the current room. There would be a limit of either the number of objects the player can carry or the maximum weight the player could carry which would be handled by the inventory class. If the player picks up gold then the inventory class would increase the players score. Some objects can't be picked up such as a building, water, etc so the inventory class would need to check if the object is moveable. Also the inventory class checks to see if the player is already has the item to be picked up. What I wanted to ask you if this is a good reason to have an inventory class? It tends to separate the code away from the main() class code. Brian

                    1 Reply Last reply
                    0
                    • realJSOPR realJSOP

                      Dave Kreskowiak wrote:

                      "Global variables", in my humble opinion, are a lazy and error prone way of moving data between objects.

                      But like in C++, you don't want to have to reallocate memory every time you need static data. "Global" (static) properties and methods are still a necessary and vital construct in C#. For instance, I have a static SessionVars object in my web apps that provide a foolproof (and type-safe) method for accessing session variables. It's "globally" accessible to the entire app (controllers, views, and other classes). I also have a static Globals class that provides properties (that don't belong in SessionVars) and methods for the entire app. Classifying all "global" objects as the crutch of the lazy programmer is pretty - well - globally wrong. Like any other construct, you have to use static classes apporpriately.

                      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                      -----
                      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                      -----
                      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                      B Offline
                      B Offline
                      Brian_TheLion
                      wrote on last edited by
                      #30

                      Hi #realUSOP. I agree that in using Global variables is a lazy approach and does not make a good programmer. The reason why I had a need to use Global variables was so classes could get variable information from each other. The inventory class would check the objects class to find out if the object location was in the same room as the player for the player to be able to pick up the object. I'm thinking of classes grouping code together but after reading my replies maybe this is not the case. Brian

                      realJSOPR 1 Reply Last reply
                      0
                      • B Brian_TheLion

                        Hi Mycroft. I'm doing my best to try and understand OOP from reading and studying examples. The code that was originally written in BASiC Will be pulled apart and put to geather so that it works under the more modern C# structure, so it is like you say a rewrite. I have a good knowledge of how the code works to do a rewrite. Brian

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #31

                        Brian_TheLion wrote:

                        Will be pulled apart and put to geather so that it works under the more modern C# structure

                        It feels like your thinking is incorrect, don't consider pulling the old code apart and restructuring it. Only inspect the code to help you define the functionality of the application NOT how it should be put together. Seriously do not try and apply basic methodology and structures to c#, everything is now an object with properties and methods. Define your objects...

                        Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                        B 2 Replies Last reply
                        0
                        • L Luc Pattyn

                          No! GetDrop is not a noun, it is two verbs, it cannot possibly be a candidate for a class. There is no main() class in my world; besides, class names use TitleCase and no parentheses. If Slippers can be gotten, they need a Get() method. If Keys can be gotten, they need a Get() method. Where are the slippers? where are the keys? does the adventurer know? No. Do all the rooms know? No. The slippers and the keys know where they are, it is information that pertains to them, and to nothing elxe. There should be an Inventory object (or even one per Adventurer), and everything inside such Inventory should derive from InventoryItem, which can hold common properties and/or common methods of gettable objects. An item's location would be an obvious property of InventoryItem; and maybe your complex test belongs there, so you don't have to repeat such test code in every single inventory item's code. Inside InventoryItem class, you probably will have good use for a static List where all items get stored, so you can search them. That is how a Room can figure what is present at any point in time. This was my last technical contribution to this topic. From all you write (and all you apparently don't pick up reading our answers) it is very clear to me you are still missing the basics of OOP. If you don't work on this (shut down your computer and go read one or two OOP books now!) you are wasting your and our time. Books tend to present their subject in a structured way, dealing with way more aspects than you are thinking of right now; random questions in a forum can't match that, they become useful after you acquired the foundation, not before. Good luck. Over and out. :java:

                          Luc Pattyn [My Articles] Nil Volentibus Arduum

                          B Offline
                          B Offline
                          Brian_TheLion
                          wrote on last edited by
                          #32

                          Hi Luc. One thing I did learn from reading your text and texts from some others is that the name of a class needs a noun word. I had thought that you could call the class any name. Strangely that is not taught in the books I have been reading (or I missed it). Thanks for your information, it was not a wasted effect. Brian

                          1 Reply Last reply
                          0
                          • P phil o

                            class A
                            {
                            private B _b = new B();

                            public int GetValue()
                            {
                            return (_b.BoolValue) ? 1 : 0;
                            }

                            public void SetValue(int input)
                            {
                            _b.BoolValue = (input != 0);
                            }
                            }

                            class B
                            {
                            public bool BoolValue
                            {
                            get; set;
                            }
                            }

                            class Program{
                            static Main(string[] args)
                            {
                            A a = new A();
                            Console.WriteLine(a.GetValue()); // prints "0"
                            a.SetValue(42);
                            Console.WriteLine(a.GetValue()); // prints "1"
                            }
                            }

                            I cannot imagine you had a look at C# without having to instantiate any class at least once. Maybe because you tried to copy some existing code which was not written with OOP in mind? You should take it from the ground, and follow some basic tutorials about C# and OOP not directly related to your task; this way you may get some important concepts that you will apply later to your actual case.

                            noop()

                            B Offline
                            B Offline
                            Brian_TheLion
                            wrote on last edited by
                            #33

                            Thanks phil for the example code, I'll study it. I find code examples useful in learning how C# works and can be applied to my own code. Brian

                            1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              Brian_TheLion wrote:

                              You have an inventory class and a get/drop class

                              No you wouldn't. You would have an Inventory class with Add, Get, and Drop methods. A class is always a noun. The methods exposed by the class are always verbs that perform operations on that noun. Your Inventory class should never output messages to the console. UI operations have nothing to do with managing the data stored by the Inventory class. This is true for ANY OOP language, including C++ and Java.

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

                              B Offline
                              B Offline
                              Brian_TheLion
                              wrote on last edited by
                              #34

                              Hi Dave. I have learn from yourself and from a few replies that the name of a class should be a noun. That presents a another problem is how do I get a message back to the player from the inventory class such as a condition where it was not possible pick up an item. I'd have a rich text message box on the form attached to a string called messages and hopefully there is a way to check for changes in the string so all I need to do is to change the text in the message string which would cause the rich text box to display the string as the string has changed. I'll study the OnPropertyChanged() command. Brian

                              D 1 Reply Last reply
                              0
                              • M Mycroft Holmes

                                Brian_TheLion wrote:

                                Will be pulled apart and put to geather so that it works under the more modern C# structure

                                It feels like your thinking is incorrect, don't consider pulling the old code apart and restructuring it. Only inspect the code to help you define the functionality of the application NOT how it should be put together. Seriously do not try and apply basic methodology and structures to c#, everything is now an object with properties and methods. Define your objects...

                                Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                                B Offline
                                B Offline
                                Brian_TheLion
                                wrote on last edited by
                                #35

                                Hi Mycroft. I may have not used the best term when I said "pulled apart" I was meaning studying the original code to see how it worked to get ideas on how the adventure should work for the new code. Having used programs like Quick Basic over the years makes it more difficult to break free from the procedure programming method, but I don't give up that easierly. Brian

                                J 1 Reply Last reply
                                0
                                • B Brian_TheLion

                                  Hi Dave. I have learn from yourself and from a few replies that the name of a class should be a noun. That presents a another problem is how do I get a message back to the player from the inventory class such as a condition where it was not possible pick up an item. I'd have a rich text message box on the form attached to a string called messages and hopefully there is a way to check for changes in the string so all I need to do is to change the text in the message string which would cause the rich text box to display the string as the string has changed. I'll study the OnPropertyChanged() command. Brian

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

                                  The Inventory class isn't responsible for communicating with the user at all, nor is it responsible for picking up items. The Inventory class just manages what is already in inventory, adding items to it, and removing items from it. Nothing else. Think of as a bag of items. Can a bag pickup items from the room? No. The Player has to pickup the items and place them in the bag. Forget OnPropertyChanged until you learn the basics of OOP. It's not going to help you.

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

                                  B 1 Reply Last reply
                                  0
                                  • D Dave Kreskowiak

                                    The Inventory class isn't responsible for communicating with the user at all, nor is it responsible for picking up items. The Inventory class just manages what is already in inventory, adding items to it, and removing items from it. Nothing else. Think of as a bag of items. Can a bag pickup items from the room? No. The Player has to pickup the items and place them in the bag. Forget OnPropertyChanged until you learn the basics of OOP. It's not going to help you.

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

                                    B Offline
                                    B Offline
                                    Brian_TheLion
                                    wrote on last edited by
                                    #37

                                    In that case it looks like I need a Player class Dave. Brian

                                    D 1 Reply Last reply
                                    0
                                    • J jschell

                                      As a note. If you want to learn how to create games then I would suggest finding one of the game frameworks and using that. There are adventure frameworks but others as well. Using one of those and creating a games (plural) provides a better understanding of the 'domain' for creating games. If you want to learn OO programming and you are using an adventure game as an excuse then learning the rules for the programming language (singular) is going to be your actual goal. The game itself is unlikely to be viable because without a detailed understanding of the 'domain' both from the business layer and the development layer your initial attempts will have problems with structure. And I speak from experience on that having attempted more than a couple games when I first started. But that is not a detriment because that will aid you in the future as you will understand intrinsically why something doesn't work versus because someone told you that.

                                      B Offline
                                      B Offline
                                      Brian_TheLion
                                      wrote on last edited by
                                      #38

                                      Thanks jschell. Having an text adventure game waiting to be written does give me something to aim for. Some books and tutorials give you examples on how each of the C# commands can be used but it's when you bring everything together in a project then I find that you learn more. Step-by-step guilds in building a program are useful and I did one of those recently. Brian

                                      1 Reply Last reply
                                      0
                                      • B Brian_TheLion

                                        Hi Bill. I have not completely given up on C#. I was just considering C++ I have a program I want to convert to C#. I have all the variable names I'm going to use and also some of the classes I'm going to create in breaking up the code into classes. To make myself more clearer I need to be able to do the following. Example: Main() class Class A Class B Main() class calls for a value or a boolean response. The result that Class A sends to the Main() class depends on a value in Class B, so Class A needs to check on value in Class B. Just before sending to Main() class the result, Class A needs to update Class B. In C# it seems that classes have strong walls and the main communication is between the main() class and the class and not between the classes themselves. I have been checking with various tests to see what is possible. So far I have managed to send a variable from the main() class to class A and have class A change the variable and have Class A send it back to the main() Class. I have not found a way for Class A to read a variable from Class B or for Class A to change a variable in Class B. Brian

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

                                        Brian_TheLion wrote:

                                        I have not completely given up on C#

                                        You cannot "give up" on something you have not invested hard work in, something you have spent more time writing questions about than you have spent studying it.

                                        «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

                                        B 1 Reply Last reply
                                        0
                                        • realJSOPR realJSOP

                                          Richard MacCutchan wrote:

                                          As others have mentioned, global variables tend to cause more problems than they solve; don't use them.

                                          He can get his "global" accessibility by creating a static class. I don't understand (and have never seen) a global static class present problems.

                                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                          -----
                                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                          -----
                                          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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

                                          A static class is a very different animal.

                                          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