You could write a simple math test program that runs through integer addition, subtraction, multiplication, and division. Basically, you ask for a number of questions, and on each question you pick a random question type and prompt for an answer. At the end, you could print statistics as to how well you did on each problem type. You could also look at the "DateTime" API to look at how to measure speed.

But yes, if you haven't delved into classes yet, you have only scratched the surface of C#. That's gonna be fun.
That's a pretty cool idea. Though StopWatch is probably easier to use for timing things than using DateTime directly.
If you are using visual studio, you can click in the left margin of your source code to put in a breakpoint (looks like a red ball). If you do this and then "start debugging" (green play button), the program will pause when it gets to that point, and you can look in the "call stack" tab to see what methods were called to get there (and even click in them to jump to that part of code), and look in the "locals" tab to see the value of variables at that point. You can use the "step over" button at the top to move to the next statement, the "step into" button to do the same but jump "into" any function-calls, and the "step out of" button to finish in the current function/method and go back to where it was called from. Also, you can click the "Play" button again to just continue running the program, or the stop button to stop it there.

This is a very useful tool, especially when something goes wrong in your code and you want to see a snapshot of things while its executing, or step through the process Smile
Having a bit of trouble on lesson 5.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneMethod
    class Program
        public static void Main(string[] args)
            string myChoice;
            OneMethod om = new OneMethod();

                myChoice = om.getChoice();

                //Make a decision based on the user's choice
                switch (myChoice)
                    case "A":
                    case "a":
                        Console.WriteLine("You wish to add an address.");
                    case "D":
                    case "d":
                        Console.WriteLine("You wish to delete an address.");
                    case "M":
                    case "m":
                        Console.WriteLine("You wish to modify an address.");
                    case "V":
                    case "v":
                        Console.WriteLine("You wish to view the address list.");
                    case "Q":
                    case "q":
                        Console.WriteLine("{0} is not a valid choice", myChoice);

                //Pause to allow the user to see the results
                Console.WriteLine("Press Enter key to continue..");
            } while (myChoice != "Q" && myChoice != "q");

        string getChoice()
            string myChoice;

            //Print the menu
            Console.WriteLine("My Address book\n");
            Console.WriteLine("A - Add");
            Console.WriteLine("D - Delete");
            Console.WriteLine("M - Modify");
            Console.WriteLine("V - View");
            Console.WriteLine("Q - Quit\n");
            Console.WriteLine("Choice (A,D,M,V, or Q: ");

            //Retreive user's choice
            myChoice = Console.ReadLine();

            return myChoice;


It keeps kicking back:

Error 1 'OneMethod' is a 'namespace' but is used like a 'type'

I've gone over the code given in the lesson, and it's the same.

Any thoughts?
But of course. Your class is called Program, therefore it should be renamed OneMethod for your code to work (if you look at the sample more closely, you will see that the class is called OneMethod).

You can continue in this tutorial, but you should know that this code is actually really bad, and a little correction will make it much better:


// all the same usings go here

namespace OneMethod
  class Program
    // insert main() verbatim, as is written in program

  class OneMethod // this name takes precedence over the namespace
    // insert getChoice() verbatim,
    // BUT put a "public" before the start of the method signature
    // so that it can be accessed from Program

Simply put, this code encapsulates the getChoice method in a separate object from Program. Typically, your program has one class that contains nothing but a Main method and any other "static" methods to help it out, usually called the Program class. The Program class's only responsibility is to set up the program flow, and should certainly never create instances of itself.
Your code doesn't match the lesson's - look again, particularly at where yours is failing on "namespace OneMethod"
I hadn't changed it for any of the other lessons, since it never specifically said that it needed to be done. I'll make the switch and see if it works afterwhile.


more of a note to self. benryves offered as an alternative to the other tutorials.
Well thanks guys. I guess my talk with merthsoft was a misunderstanding on my part when I asked him about them a few days before asking about the above code. Changing the class fixed the issue. Since it never had mentioned that before, I merely thought it was something that VS did by itself. Now I know a little more about what I'm looking at, I'll try not to make that mistake again in the future Smile
tifreak8x wrote:
Well thanks guys. I guess my talk with merthsoft was a misunderstanding on my part when I asked him about them a few days before asking about the above code.
Wait a minute, what'd I say?
I don't recall word for word on that, it was just hinted at not being important, and then you were happy I was going on to methods. About all I remember of that. I guess I didn't connect the two together.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum