oval
Apr 27 2006, 10:18 PM
Click to view attachmentClick to view attachmentThis tutorial will help get you started with C# Sharp. These tutorials will assume that you are using the Visual Studio environment. If you are just curious to test out some code, then you can copy and paste this code into your CS file, however, before doing so, make sure to name your project the same as the namespace on the code. But since this first program is fairly easy, it will not hurt to type it out. It is fairly easy and short. Also, this program is highly commented so it should be easy to follow along. Comments will have 2 forward slashes before them '//' trailing with the comment. Well before looking at the code, I just want to summarize what the following lines of code will do. Console.WriteLine(); <----- Writes a string of characters on the console in it's own line. So writing Console.WriteLine("Hello World"); would result in Hello World displaying on your console and have the cursor move to the next line down. Console.Write("Hello World"); would also display Hello World however the cursor would be next to the word and not the line below. Console.ReadLine(); <------ This nifty method will allow you to take in user input. Whether the user input is numeric or alphabetic, it will take the input as a string or text. So you cannot use it in any mathematical operations right away. That is if the user was to enter 5 and you want to add 4 to that 5, you could not, right off the bat anyway. However we will go into that later. Okay, now observer the code below: using System; CODE ==================== BEGIN C# CODE ===================================== namespace testProg { ///<summary> /// Test Programming ///</summary> class helloProg {
[STAThread] static void Main(string[] args) { //Declare a String variable. Name it userName string userName; Console.Write("Console Asks - Please Enter your Name: "); //Place the user input into the variable userName with //Console.ReadLine() userName = Console.ReadLine(); //Skip a line for nicer formatting Console.WriteLine(""); //On the next line, display the input. //{0} is where the variable value will go. It //is followed by a comma and variable name userName Console.WriteLine("Hello {0}!", userName); Console.WriteLine("Press Enter to Continue"); //The Console.Readline will pause the program until you //press [ENTER]. Then it will exit. Console.ReadLine(); } //end main
} //end class } //end namespace
=========================== END C# CODE ================================
Okay aside from the information I provided before the code, I think the comments explain pretty much what is going on within this program. However, I want to further elaborate how we placed the user input into the variable userName. By setting first we declared userName as a string (i.e. string userName;) Later in the program, we said userName is equal to what the user enters, userName = Console.ReadLine(); This is what did the trick. now we just output user name in one of our Console.WriteLine's and Voila. Modify the variables, add lines and variables and get acquainted with it yourself. I'll be back soon to provide another lesson. By the way, I hope I am able to upload my attachment. The code on this one looks kinda sloppy. It's in .pdf format.
Reply
iGuest
Sep 8 2008, 03:38 PM
c# console application question (card game)
Lesson #1 - Introduction To C#
I want to know about how to do about the following question. Create a simple GUI application to simulate a two player Game. A detailed description of the requirements follows: Player 1 makes a guess. It compares with a pseudo random number. If they match, player 1 wins and the game is over. In case of a mismatch, player 1 passes the random number to player 2 and a challenge begins. Player 2 also makes a guess and then compares the number with the random number it has received. If the numbers match, player 2 wins the challenge and the game is over. In a case of a mismatch player 2 discards the random number and generates another random number to compare with the guessed number. If they match player 2 wins the challenge and the game is over. In the case of a mismatch, player 2 passes the random number to player 1 and a challenge begins. The sequence is to be repeated till a winner emerges. Create player 1 using .Net technology and player 2 using Java technology to simulate the game and use a XML file to establish the communication between the players. You should be able to display the current player in both interfaces with appropriate messages to display the winning player and to indicate the game is over. -reply by Buddhika
Reply
Recent Queries:--
console c# - 0.02 hr back. (1)
-
c# where console - 3.23 hr back. (1)
-
c# console programing - 6.57 hr back. (1)
-
c# console codes - 7.49 hr back. (1)
-
c# console user input - 7.87 hr back. (1)
-
visual-studio console-application tutorial how-to - 10.60 hr back. (1)
-
c# exit - 12.51 hr back. (1)
-
c# console application examples - 12.61 hr back. (1)
-
c# console tutorials - 13.13 hr back. (1)
-
console appllication in c# - 19.85 hr back. (1)
-
how to declare a array c# console application - 20.75 hr back. (1)
-
c# console application tutorial - 23.07 hr back. (1)
-
console application c# code exit - 24.45 hr back. (1)
-
c# console - 9.28 hr back. (3)
Similar Topics
Keywords : introduction, c, lesson, 1, console, application
- Creating Your First Application
(1)
Lesson1 :introduction To Visual Basic
(2) QUOTE Hi, Friends, Welcome to Visual Basic tutorial! You have come to the right place to
learn Visual Basic Programming. I like to share the knowledge with you because I have intense
passion on Visual Basic. I wish you could spend some time reading the tutorial so that you can
really acquire the basic skills in Visual Basic programming. Happy Learning! 1.1 What is
computer programming? Before we begin, let us understand some basic concepts of programming.
According to Webopedia, a computer program is an organized list of instructions that, when executed....
C# Tutorial : Lesson 9 - Constructors & Destructors
(0) The need for Initialization A class contains data members (variables) and member
functions. Initializing the values of these data members is essential, at times. Take a look at the
following scenarios:- CODE int MyNumber; Console.WriteLine("My Number = {0}",
MyNumber); This block of code declares a variable MyNumber and then prints it on the
screen. However, when you try to execute these instructions, an error Use of unassigned local
variable 'Product' will be generated. This is because, we are trying to use the value of
My....
C# Tutorial : Lesson 8 - Functions/methods
(0) The programming model has gone through many refinements, each change improving upon the model. One
of the early changes was the inclusion of Subroutines or Subprograms. As the names suggest, these
are fragments of code within a program. They offer the following advantages:- Reduction of code
duplication by offering re-usability Simplifying program logic by decomposing the program into
smaller blocks Improving readability of the program Why do we need functions?
Consider the following program:- CODE using System; namespace ConsoleApplication1 { ....
C# Tutorial : Lesson 7 - Creating Value Types & Reference Types - Part II
(1) foreach statement This statement is explicitly used to traverse through arrays. The
benefit of using foreach over the normal for statement is that it is not needed to check the
size of the array while using the former. Syntax:- foreach(type identifier in expression) {
statement 1; statement 2; .... } Suppose we have an array StudentNames containing the name of all
the students in a class. We need to display the name of each one of them on screen. First we will
see how it can be done using the for loop. CODE string[] StudentNames = new s....
C# Tutorial : Lesson 6 - Creating Value Types & Reference Types - Part I
(0) Value Types & Reference Types In C#, Variables are either value types or reference types
depending on what they store, values or references. By reference we imply that the variable holds
the memory address of another location where the actual value is stored. All built in data types -
Int, Char, String, Float, Boolean, etc are value types while classes are reference types. The
following is a diagrammatic representation of these two types. In this picture there are two
variables Num1 and Num2. Both of these being integer variables store the values directly.....
C# Tutorial : Lesson 5 - Encapsulation & Abstraction
(0) Encapsulation & Abstraction Two concepts that go together in the object oriented approach
are Encapsulation & Abstraction. Abstraction is the representation of only the essential features of
an object, while Encapsulation is the hiding of the non-essential features. Think of a person
driving a car. He does not need to know the internal working of the engine or the way gear changes
work, to be able to drive the car (Encapsulation). Instead, he needs to know things such as how much
turning the steering wheel needs, etc (Abstraction). Consider the example from ....
C# Tutorial : Lesson 4 - Object Oriented Programming
(2) Object Oriented Programming Object Oriented Programming is a methodology modeled on real
life. It comprises of the basic unit, an object, being used in implementing a program. Think of all
the objects around you - cars, buses, birds, trees, etc. You will find countless ones of them,
everywhere you go. In order to tackle this huge number, we started classifying them, thus came the
term Class. Class A class is a composition of the theoretic characteristics (attributes and
properties) of an object and the things it can do - behaviors, methods and features. Tak....
C# Tutorial : Lesson 3 - Programming Constructs
(1) Conditional Branching By branching we imply, having different paths for execution.
Conditions are used to determine which statements need to be executed. Suppose, you have a program
to store the details of employees. Depending upon the post of the employee, there would be various
fields associated with it. A department head, for example, would have a property denoting the
department he heads, etc. We use conditional branching in such a scenario. C# provides the
following conditional constructs:- if .. else Syntax:- if ( ) { statements } else { statement....
C# Tutorial : Lesson 2 - Variables & Operators
(0) Variables A Variable is a named location that stores a value. Although variables are
physically stored in the RAM, their actual memory address is not known to the programmer. We can use
the variables via the name we give them. These are the rules for naming a variable:- The name must
begin with a letter or an underscore & can be followed by a sequence of letters (A-Z), digits (0-9)
or underscore (_) Special Characters such as ? - + * / \ ! @ # $ % ^ ( ) { } , ; :
. cannot be used in the variable name. A variable name must not be the same a....
C# Tutorial : Lesson 1 - Hello World Program
(0) This is the first installment of my venture to explain the bits and pieces of C# that I have managed
to learn at NIIT. In this lesson we would be creating the Hello World application. STEP 1 : Create
a New Console Application in Visual C# The IDE automatically adds the following code:- CODE
using System; using System.Collections.Generic; using System.Text; namespace HelloWorld {
class Program { static void Main(string[] args) { }
} } Lets take a look at the first 3 lines. All of these lines begin with t....
Installing Vb.net
Part 1 - Obtaining, installing, and creating your first application (3) Well I didn't see anything on here about how to get started with vb .net, so I figured that I
would write a small tutorial on how to get started with programming in VB .Net. If I get a lot of
positive responses, I'll continue, if not I won't. Step 1: Obtaining Visual Basic .NET
Microsoft in recent years has made a giant step in allowing hobbyists to learn program without
having the burden of buying expensive software. This is a great business idea on their part, because
it allows more people to become interested in their software, therefore, increasing th....
The .NET Framework & CLR : Basic Introduction
(1) The .NET Framework is Microsoft's answer to the JAVA platform. With heavy investments going
into the development, one can't question the push Microsoft is giving to this technology. Living
in the hi-tech industry and not interacting with the .NET Framework is highly unlikely, considering
the market share that Microsoft's Operating Systems have. I am writing this article as a means
to further the knowledge that I would be gaining while learning the MCAD Training Kit (maybe in the
process, helping out some beginners). For those of you who don't know what ....
Lesson #3 - Basic Math Operators And Random #s
Lesson #3 - Basic Math Operators and Random #s (0) In this lesson I will cover how to use basic math operations, well addition really but you can also
use subtraction , division and multiplication . I would also like to note that when doing
division, if variabes of int type are used you will not get any remainders (i.e. n.345984). To be
able to work with real numbers, numbers with decimals, you can use float. Below is a way to declare
a float and assign it a value: float floatNumber; float Number = 28.47f; Aside from
generating random numbers and basic math operations, we will also incorporate an if statement a....
Lesson #2 - Switch Statement In C#
Using the Switch Statement in C# (1) In the previous lesson we demonstrated did a basic input output application which asked your your
name and replied with a general greeting using the name you entered. In this lesson we are going
to learn about a conditional statement called the switch statement. Usually if and if else
statements are taught before switch statements. Although these are very useful, I find the switch
to be easier and more fun to use. The program written below is very similar to the previous
program where the user is asked to enter their name, however now the program will loo....
Looking for introduction, c, lesson, 1, console, application
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for introduction, c, lesson, 1, console, application
|
advertisement
|
|