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

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

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

                                Brian_TheLion wrote:

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

                                It will. C# is a rich language that can handle just about any problem you can think of. But, as I and others keep saying, you need to learn and understand the language, and its rules, first.

                                Brian_TheLion wrote:

                                I'm still trying to find a way of one class changing the variables in another class if that's possible.

                                That is what Properties and Methods are there for.

                                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

                                  F Offline
                                  F Offline
                                  F ES Sitecore
                                  wrote on last edited by
                                  #42

                                  #realJSOP wrote:

                                  I don't understand (and have never seen) a global static class present problems

                                  You've lived a very sheltered life :)

                                  realJSOPR 1 Reply Last reply
                                  0
                                  • B Brian_TheLion

                                    After learning C# for a while it seems that you need to keep within certain rules to have the program compile. 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. Maybe some programs are better suited to C# than others. I do like being able to design a user interface. All programs seem to have a user interface as I've never come across a program that only runs under the DOS prompt. Imagine what programs like Audacity would be like if they only used the DOS prompt. I'm being drawn towards C++ as it does allow global variables compared to C#. I know that it's not good to use global variables and most variables should remind within their own class but it's not always easy to design a program like this and the program I have in mind that I want to write has many varables between classes. I could write it with less classes but I want to have classes for certain purposes that can be reused in other programs. It also makes the program easier to deal with when changes are made. Comments are welcome thanks. Brian

                                    F Offline
                                    F Offline
                                    F ES Sitecore
                                    wrote on last edited by
                                    #43

                                    I've knocked up this basic template to give you an idea what people are talking about. There is a "global" object you need to track like the player and also the current location, so you can either create these as an instance of a variable and keep a hold of them, passing them to functions\events as needed, or you could create a "static" class that will hold a reference to your player object and current location object. As I said, it's the basics, you'd need to tweak for things like containers as game objects also so you could pick up a bag, or put a small bag inside a big bag etc.

                                    public class GameObject
                                    {
                                    public string Name { get; set; }
                                    public int Weight { get; set; }
                                    }

                                    public abstract class Container
                                    {
                                    public int MaxWeight { get; set; }
                                    public int MaxItems { get; set; }

                                    public List Objects { get; private set; }
                                    
                                    public Container() : this(0, 0)
                                    {
                                    
                                    }
                                    
                                    public Container(int maxWeight, int maxItems)
                                    {
                                        this.Objects = new List();
                                        this.MaxItems = maxItems;
                                        this.MaxWeight = maxWeight;
                                    }
                                    
                                    public GameObject Find(string name)
                                    {
                                        return this.Objects.FirstOrDefault(o => o.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
                                    }
                                    
                                    public bool CanContain(GameObject gameObject)
                                    {
                                        // if max items is set make sure we have room
                                        if (this.MaxItems > 0 && Objects.Count >= this.MaxItems)
                                        {
                                            return false;
                                        }
                                    
                                        // if max weight is set make sure we have capacity
                                        if (this.MaxWeight > 0 && Objects.Sum(o => o.Weight) + gameObject.Weight > this.MaxWeight)
                                        {
                                            return false;
                                        }
                                    
                                        return true;
                                    }
                                    

                                    }

                                    public class Player : Container
                                    {
                                    public bool Get(Container container, string name)
                                    {
                                    // rather than returning true\false you can return an enum that is specific to
                                    // why the get failed
                                    GameObject targetObject = container.Find(name);

                                        if (targetObject == null)
                                        {
                                            return false;
                                        }
                                    
                                        if (!this.CanContain(targetObject))
                                        {
                                            return false;
                                        }
                                    
                                        container.Objects.Remove(targetObject);
                                        this.Objects.Add(targetObject);
                                    
                                        return true;
                                    }
                                    

                                    }

                                    public class Room : Container
                                    {
                                    public string Name { get; set; }

                                    public Dictionary Exits { get; set; }
                                    
                                    public Room()
                                    {
                                        this.Exits = new Dictionary
                                    
                                    B 1 Reply Last reply
                                    0
                                    • F F ES Sitecore

                                      #realJSOP wrote:

                                      I don't understand (and have never seen) a global static class present problems

                                      You've lived a very sheltered life :)

                                      realJSOPR Offline
                                      realJSOPR Offline
                                      realJSOP
                                      wrote on last edited by
                                      #44

                                      Or just maybe, I've never abused the construct. :) In all actuality, I was annoyed with the lack of support for global vars when I moved from C++ to .Net, but I adapted.

                                      ".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

                                      D 1 Reply Last reply
                                      0
                                      • B Brian_TheLion

                                        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 Offline
                                        realJSOPR Offline
                                        realJSOP
                                        wrote on last edited by
                                        #45

                                        I came from C++ to .Net, and I disagree. When used appropriately, global vars are a viable - and even necessary - part of C++.Simply replace the global vars with a static class that contains the vars, and you're off an running. I don't understand how this would be a bad thing, and will continue to use my static globals class for this kind of stuff...

                                        ".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

                                        D B 2 Replies Last reply
                                        0
                                        • realJSOPR realJSOP

                                          I came from C++ to .Net, and I disagree. When used appropriately, global vars are a viable - and even necessary - part of C++.Simply replace the global vars with a static class that contains the vars, and you're off an running. I don't understand how this would be a bad thing, and will continue to use my static globals class for this kind of stuff...

                                          ".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

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

                                          Is it weird that I rarely use global variables? I've used static classes with constants defined for "magic values" and objects that are required throughout the code, like a logger, but true global variables, not really.

                                          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
                                          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