Skip to main content

Posts

Showing posts with the label C#

C# ?: (Question Mark Dot) Operator

I liked this operator. It is called "ternary" operator too. I can use it instead of basic "if" statements. Syntax of this: condition ? consequent : alternative And the code sample:   1 2 3 4 5 6 7 8 9 10 using System ; class Operators { static void Main () {start: //a label to start again Console.Write( "Do you want to continue? (y, n): " ); string answer = Console.ReadLine(); Console.WriteLine(answer == "y" ? "Congrats!" : "See you later!" ); goto start; } }

A Sample of C# Variables and Data Input From User

This is a"how to" to get two different datas from user and define them to two different variables: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 using System; namespace Variables { class Program { static void Main(string[] args) { starthere: Console . WriteLine( "Please enter first number:" ); int first = Convert . ToInt32(Console . ReadLine()); Console . WriteLine( "Please enter second number which is greater then the first:" ); int second = Convert . ToInt32(Console . ReadLine()); if (first < second) { Console . WriteLine( " \n Let's count them from smaller to greater: \n " ); for ( int i = first; i <= second; i ++ ) { Console . WriteLine(i); } } else ...

My First C# Program

C# is a popular programming language produced and mainteined by Microsoft. This page is included basics of C# programming language and my learning steps with some code snippets. On following lines, there is my first program's codes. It runs in "console" application. using System ; namespace Basics { class Program { static void Main ( string [ ] args ) { Console . Title = ( "Started to Learn!" ) ; // Set a title for CMD window. basla : // a flag to return here back. Console . WriteLine ( "What is your name? " ) ; // Printing to the screen   string ad = Console . ReadLine ( ) ; // set a variable named "ad" and waiting for user input. Console . WriteLine ( " \n How old are you" ) ; // Text which was printed on the screen. "\n" flag is for jum...