1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development C# programming, advice please.

Discussion in 'Software' started by dave_c, 17 Jul 2015.

  1. dave_c

    dave_c Minimodder

    Joined:
    31 Jul 2009
    Posts:
    436
    Likes Received:
    11
    Okay all, im asking here as a last resort. Iv'e spent the last week looking for this online (and yes i have googled it to death)

    I'm trying to learn C# as my very first programming language. NEVER touched programming before. Ive found a hell of a lot of tutorials telling me i need to type things like:

    Console.WriteLine("Hello World");
    Console.ReadLine();


    im some-what proud i remembered that (go on, someone tell me I wrote it wrong, lol). but no tutorials i have watched or read have explained things like WHY the () what does it mean, what does it tells the computer to do?

    This may seem obvious to a lot of you and im sure i could find this one answer if i searched for long enough but it would be awsome if someone could point me toward a resource which explains these things naturally. Otherwise they just turn into another "cook book" style, type this then type this, which is useless for actually learning.

    Thanks all, I've already watched maybe 20 hours of tutorials on C# but im not finding anything new. Books resouces are welcome too.

    Really appreciate any help any veterans can give.
     
  2. GoodBytes

    GoodBytes How many wifi's does it have?

    Joined:
    20 Jan 2007
    Posts:
    12,300
    Likes Received:
    710
    First time explaining programming, lets see how good I do:

    The parentheses "()" specifies the list of arguments that a function takes, if any.

    So, 'Console' is the class. You can be seen as an object or a group that contains many functions which can set/do stuff or get information about something (usually related to the class or object) in a brief manner. It has: BackgroundColor, BufferHeight, BufferWidth, WriteLine, ReadLine, and many many others. Here is the entire list:
    https://msdn.microsoft.com/en-us/library/system.console(v=vs.110).aspx

    WriteLine, and ReadLine are functions. All functions, ends with parentheses, and hence who you identify them with ease.

    To understand the parentheses, we need to understand how a function is formed
    A function is formed like so:
    Code:
    void myFunctionName (int someInput) {
        someInput += 3; // add 3 to someInput. This is the same as if I did: someInput = someInput + 3;
        // my ultimate function of D00000000000mm
    }
    
    The squiggly brackets "{}" forms a group for the computer (well the compiler) to understand what starts and ends.

    "void" in the above example, means what to return. 'void' means I return nothing. If I wanted to return a number, like an integer, I would put 'int' instead of 'void', and my last line of code within my {} would be 'return 0', or 'return 1', or 'return 2', or what ever non-decimal point number you want. For decimal point number see: double, and float.

    'myFunctionName' is the name of the function. You can put anything you want except spaces. No spaces in names allowed, because else the compiler would get confused if its a function name or something else to look for. Sure it COULD guess, but on big projects it would be cause sever performance degradation when compiling, and can get confused with other things causing bugs that would be a pain to find. So no spaces.

    Content inside the parentheses that follows the function would be what it expects to receives. The argument of a function. In my example above, I say that I expect a integer (number without a decimal point), which I want to STORE in a number of my own called 'someInput' so that I can work with it. In my function above, it adds 3 to the number I get.

    You can have many arguments if you want for a function, just separate them with comas. For example:
    Code:
    void myFunctionName (int numberReceived, String messageReceived, double doubleValueReceived) {
    }
    
    Or it can be empty like so:
    Code:
    void myFunctionName () {
    }
    
    So, now that we understand how a function is made, I think it makes now, for you, more sense on why they are parentheses on function calls. It is to list, if any, the arguments of the function.

    Normally, a function takes arguments to do things with it, and usually return a result.

    The idea of functions is to do many things for you. Either you make them, or you use what is created, in your case: WriteLine, and ReadLine. All the back end stuff in showing or getting stuff from the console window (command prompt), is done for you. Instead of typing a big block of code to show text on it (what WriteLine does), you just call that function, and you can use it multiple time in your code. The benefit of this, beside simplifying code, and keeping ones sanity, it is that if you find a bug in one of your function, you only need to fix it once, and not everywhere in you code, multiple times which could take hours, and navigating pages and pages of code that replicate itself. So ideally, you want to use functions wherever you can.


    If you want tutorials that different than the usual tutorial and get you started doing cool stuff, and not the boring "Hello World" (although important to understand the pure basic of everything)

    Check out these videos:
    https://www.youtube.com/watch?v=Yj0G5UdBJZw&list=PLEbaEyM-xt9mVQEAXGlRRmbO2Qp_oqF-n

    A small update on the above first video. This was filmed before Microsoft introduced: Visual Studio Community. This edition of Visual Studio is the Professional version, but FREE, and YES you can do commercial software with it, if you want (your business must be 7 employees or less, iirc, unless you are working on an open source project with it within a company. Then you can install it on as many computer you need, as long as it is used to work on open source projects). The Express edition talk about in the video is no longer available, or will be remove if its not yet, and was a stripped down version of Visual Studio. So when you go to Microsoft website, be sure to get the Community edition.
     
    Last edited: 18 Jul 2015
    dave_c likes this.
  3. theshadow2001

    theshadow2001 [DELETE] means [DELETE]

    Joined:
    3 May 2012
    Posts:
    5,284
    Likes Received:
    183
    You need to understand a little bit about object oriented programming concepts in this case. An object is something which contains both information and actions. The information is the data which the object stores, processes and generally handles in order to achieve some task. The actions are the things the object does with the information in order to complete some task. These can be called methods or functions. Usually methods in C#

    Although not entirely correct, for the purposes of this post we can consider the Console as an object. Console has all the information and actions that you need to write out to a console window from your applications. You can also read in from the console. Console has been constructed and programmed for your convenience by Microsoft. All of the real tricky stuff has been done for you and you just have to use it. To access the methods in Console you use what's called the dot operator. So you write Console in visual studio followed by a dot and intellisense brings up a menu of the different methods you can access in Console.

    The WriteLine method strangely enough, writes a line out to the Console. But it can't mind read, so you need to tell it what you want to write out. This is where the brackets come in. If a method requires some information in order to complete it's action, the information is usually placed in brackets after the method name. What you put into the brackets are called Arguments. In this case you have 1 argument, called a String. A String is a series of characters stuck together. Strings are denoted by the "double quotes". You have two words but only one set of double quotes, so its just one string.

    ReadLine is a method also. Oddly enough it reads a line in from the console. ReadLine is a method but it doesn't require any information input into it in order to work. So you just have blank brackets or zero arguments. It knows where the console is. It knows how to read the information. It doesn't need anything further from the programmer in order to work and so we get ( ).

    As well as taking arguments a method can also return information. Once a method has completed its action it can give back some information. A method takes arguments on the right side (in brackets) and shoots some result out the other side. So you could take something like this:

    Code:
    using System.IO;
    using System;
    
    class Program
    {
        static void Main()
        {
            string timmy;
            timmy = Console.ReadLine();
            Console.WriteLine(timmy);
        }
    }
    This code declares a string variable called timmy. It reads a line in from the console and returns that line. It stores the line in timmy. Then WriteLine takes timmy as an argument and writes it back out to the console. So you should see whatever it is you typed get printed out again.

    Programming isn't the easiest thing to get into on your own. I'd recommend trying to find some classes just to get you started. Having someone there showing you things is night and day compared to sitting with some videos. Once you get up to a certain level, the video tutorials and books will become easier to processes.

    Also bear in mind that you will not understand everything straight away (like why calling Console an object isn't quite accurate) If you keep slogging at it, the stuff you just have to blindly accept will start making sense.
     
    Last edited: 17 Jul 2015
    dave_c likes this.
  4. dave_c

    dave_c Minimodder

    Joined:
    31 Jul 2009
    Posts:
    436
    Likes Received:
    11
    Firstly, thankyou both for trying so hard to teach me. it's really appreciated.

    Funnily GoodBytes, i've followed jerry on youtube since before he was layed off by microsoft and have looked at the codegasm stuff before... but, bloody hell the guy types and talks fast :D

    I'm going to print out both of your replies so that i can study them in depth and take my own notes on what you have both said. It's A LOT of information to read of a computer screen but so far you've both explained it far better than a vast number of published books i have read.

    There seems to be some kind of mental block with these published programmers where they assume a much higher understanding of syntax than a complete novice has and expect much higher rates of retention than is physically possible (at least for me, maybe im just a bit slow).

    Again, really appreciate the help. Thankyou.
     
    GoodBytes likes this.
  5. theshadow2001

    theshadow2001 [DELETE] means [DELETE]

    Joined:
    3 May 2012
    Posts:
    5,284
    Likes Received:
    183
    Jerry's videos move fast. I've watched through them and thought they weren't really suitable for absolute beginners. I would think a small grounding would be necessary before going through his videos. I think they are better as a reinforcement tool than a lesson.

    Among the first programs I have done were thing likes: If you enter a value less than 5 euro, what is the fewest number of coins that can be used to create that amount. So entering 0.21 would output 20 cent and 1 cent. Or entering 1.55 would output 1 euro, 50 cent and 5 cent.

    Others were to enter a value in Fahrenheit and output the equivalent in Celsius.

    To achieve programs like these you need to understand about console input and output, floating point variables and variable assignment (x = y) and the mathematical operations: add, subtract, divide, multiply and modulus (modulus is an important one but I don't remember doing much of it in maths class in primary / secondary school)

    Again with these kind of questions there are no classes or objects or functions or any of that, Just variables and basic operations. Starting off requires getting tasks like the above done. Then introducing concepts like functions, then branching (if/else) and looping (while/for). Then classes and objects and so on. Each new concept then needs a number of exercises to be completed to learn and reinforce the ideas, before moving on to the next.

    No where near as fun as what Jerry does, but when I was given problems like these after being thought the necessary foundations I enjoyed the challenge involved in completing them none the less. Its also why I do recommend trying to find a class, I'm not sure how old you are but you could probably find after school classes if that's where you are. Or night classes if you are a bit older. Working with and learning from other people is really important in programming. It shakes you out of the small box you can occasionally find yourself in.
     
    GoodBytes likes this.
  6. dave_c

    dave_c Minimodder

    Joined:
    31 Jul 2009
    Posts:
    436
    Likes Received:
    11
    I've actually been looking (hard) for classes but the only ones my local colleges and universities do (or any within a 20 mile radius) are degree level. I've also had a good look for private tutors, found one in the whole of Liverpool which i was quite shocked about. have already contacted him but the logistics are proving difficult with that too.

    Im 30 :) I would genuinly love to learn from/with other people but for some reason which i cannot fathom, it is not a lesson which is well taught. A friend suggested that this was because most people learn it from videos online. regardless though, no tutors or classes available.

    Needless to say, im passionate about learning this and WILL make it happen. I may just end up taking a much longer time learning it than i would if i had the resources available.
     
  7. deathtaker27

    deathtaker27 Modder

    Joined:
    17 Apr 2010
    Posts:
    2,238
    Likes Received:
    186
    I'm refreshing myself on code and i found that once I have the foundations finding challenges (eg: https://projecteuler.net/archives) and google for what I want to do helps be a lot.

    Also asking people who know code who then point out the mistakes I make is also very useful.
     
  8. theshadow2001

    theshadow2001 [DELETE] means [DELETE]

    Joined:
    3 May 2012
    Posts:
    5,284
    Likes Received:
    183
    OK well Ive completed degree level courses in programming when doing my own engineering degree and again recently as Im back in college part time. I wouldn't let that put you off.

    College is essentially where I learned the foundations of programming starting with 0 programming experience. It was also where I got the simple examples in my previous post.

    I actually started out on C. C is a funny one because the basics are really simple but once you start doing anything remotely useful on it the difficulty goes up a lot. So its a good language to learn the fundamentals on before switching to something like C# or Java which should enable you to do more things with lower complexity than trying to do the same in C.

    Anyway I would give a programming 101 type course a shot at a local university. Or even better if you have some sort of technical colleges where the approach is less academic. The main thing to look for is that they do labs. The labs are where you actually learn programming. They usually assume 0 programming experience. This may change eventually as the kids seem to be learning programming younger these days.

    Also there are some introduction courses on Lynda. You can get a free trial there.
     
  9. Landy_Ed

    Landy_Ed Combat Novice

    Joined:
    6 May 2009
    Posts:
    1,428
    Likes Received:
    39
    Dave, have a look at coursera.org, lots of free courses.
     
  10. megamale

    megamale Minimodder

    Joined:
    8 Aug 2011
    Posts:
    252
    Likes Received:
    3
    This.

    I was in the same position a couple of years ago. All I have done is the C# course on Pluralsight (subscribed for a couple of months). It was a bit "cookbook" for my liking as the OP said, but by far, the most learning I had was from completing challenges. The two main ones I use are
    - Project Euler
    - CodeEval

    Nothing beats learning by doing in my opinion.
     
  11. theshadow2001

    theshadow2001 [DELETE] means [DELETE]

    Joined:
    3 May 2012
    Posts:
    5,284
    Likes Received:
    183
    I've checked out CodeEval, it seems to be quite good. I'm working through the "find the longest common substring" challenge.
     
  12. javaman

    javaman May irritate Eyes

    Joined:
    10 May 2009
    Posts:
    3,987
    Likes Received:
    191
    pluralsight is a useful resource. Unfortunately it's a paid for resource but there is a free trial. "Becoming a .NET developer" uses C# and will show you how to set up your IDE and give a bit of background into Object Orientated programming.

    Agree with theshadow2001. In Uni we started with C for engineering modules and java for computer science modules. In work we use C# and it is a fairly powerful language that is simpler than C/C++ and less frustrating than java.
     

Share This Page