A1VBCode Forums » .NET Programming » C# » Learn Csharp Basics in 1 Hour - Csharp Tutorial For BeginnersInstantForum 2016-2 FinalA1VBCode Forumshttp://www.a1vbcode.com/vbforums/A1VBCode ForumsWed, 14 Apr 2021 19:34:52 GMT20RE: Learn Csharp Basics in 1 Hour - Csharp Tutorial For Beginnershttp://www.a1vbcode.com/vbforums/FindPost31979.aspxThese are fundamentals of C#, if you are a beginner then you must have knowledge of all these aspects.<br>Wed, 29 May 2013 08:47:35 GMTannaharrisLearn Csharp Basics in 1 Hour - Csharp Tutorial For Beginnershttp://www.a1vbcode.com/vbforums/FindPost31938.aspx<b>Introduction</b><br>
<br>
As with all programming languages, c#.net has its own syntax, In this chapter, we'll take a look at the elements of the c#.net language: variables, constants, data type, operators, conditional statements, loops.<br>
<br>
<b>How To Declare variables?</b><br>
<br>
Variables are used to store data in a program, The syntax for declaring a variable is:<br>
<br>
Data_Type VariableName;<br>
<br>
Data_Type: is the type of data that we want to store in our declared variable.<br>
<br>
<b>How To Declare Constants?</b><br>
<br>
a constant represents permanent data that never changes, The syntax for declaring a constant is:<br>
<br>
const int myConstant = 12;<br>
<br>
<b><b>What's Data Type?</b></b><br>
<br>
Every variable must have a data type. A variable's data type determines the values that the variable can contain, C#.net has a wide range of data type:<br>
<br>
byte, short, int, long, string, char, bool, float, double,decimal,... etc.<br>
<br>
<b><b>What's an operator?</b></b><br>
<br>
An operator is a symbol that causes C# to take an action.<br>
<br>
<b>How to use operators?</b><br>
<br>
Operators let you manipulate your data, It makes working with alphabetic characters and numeric characters easy, C#.Net comes with plenty of built-in operators:<br>
<br>
<b>Assignment Operators</b><br>
<br>
After a variable is declared, you can assign a value to it by using an assignment statement. In C#.net, the equal sign (=) is used as the assignment operator. The syntax for assignment statements is as follows:<br>
<br>
double pi = 3.14;<br>
<br>
string text = "Brainy";<br>
<br>
<b><b>String Concatenation operators</b></b><br>
<br>
The plus sign (+) allows us to concatenate strings. The syntax for string concatenation operator is as follows:<br>
<br>
string message = "Welcome" + " To " + "How2Prog " + "Space";<br>
<br>
<b><b>Arithmetic operators:</b></b><br>
<br>
C#.net supports various arithmetic operators for all floating-point and integer numbers. These operators are + (addition), - (subtraction), * (multiplication), / (division), ^(Exponentiation) and % (modulo).<br>
<br>
int sum = 3 + 6;<br>
<br>
int product = 6 * 2;<br>
<br>
double division = 40 / 5;<br>
<br>
double expo = Math.Pow(10, 7);<br>
<br>
<b>Increment and Decrement Operators</b><br>
<br>
There are two more shorthand operators for incrementing and decrementing a variable by 1 is as follows:<br>
<br>
//increments var by 1<br>
<br>
number++;<br>
<br>
//decrements var by 1<br>
<br>
number--;<br>
<br>
<b>Comparison operators</b><br>
<br>
Comparison operators compares two values and determines the relationship between them, for example:<br>
<br>
bool result1=4>2; //result1=true because 4 is greater than 2<br>
<br>
bool result2=5<1; //result2=false because 5 is not less then 1<br>
<br>
bool result3 = 10!= 5; //result3=true becaus 10 and 5 are not equal<br>
<br>
bool result4 = 3 == 6 / 2; //result4=true becaus 3 and 6/2 are equal<br>
<br>
<b>Logical operators</b><br>
<br>
C#.Net provides the following bitwise/Logical operators:<br>
<br>
//And (&&) operator: Performs an And operation:<br>
<br>
bool result1 = (2 > 1 && 4 > 2); // true because all conditions are true<br>
<br>
//Or (||) operator: Performs an Or operation:<br>
<br>
bool result2 = (2 > 3 || 1 < 2); // true because there is a true condiition<br>
<br>
<b>if... else Statements </b><br>
<br>
If statement enables you to evaluate one or many conditions and take action based on that condition. its syntax is:<br>
<br>
if( /*Statement that can be either true or false*/)<br>
<br>
{<br>
<br>
//Do Someting<br>
<br>
}<br>
<br>
And here's an example putting if statement to work:<br>
<br>
if (Age == 24)<br>
<br>
{<br>
<br>
Console.WriteLine("We have the same age");<br>
<br>
}<br>
<br>
The logic of the precedent Example is that it tests whether the Age is less equal to 24. If<br>
<br>
so, it prints:<br>
<br>
We have the same age<br>
<br>
Suppose we wanted to execute some code for either of the two or many possible results of a condition. We can perform this task easily using an else statement along with an if statement, it's syntax is as follows:<br>
<br>
if( /*Statement that can be either true or false*/)<br>
<br>
{<br>
<br>
//Do Someting<br>
<br>
}<br>
<br>
else<br>
<br>
{<br>
<br>
//Do Someting<br>
<br>
}<br>
<br>
Take a look at this example:<br>
<br>
if (password=="123456")<br>
<br>
{<br>
<br>
Console.Write("Login succeeded");<br>
<br>
}<br>
<br>
else<br>
<br>
{<br>
<br>
Console.Write("Error Login");<br>
<br>
}<br>
<br>
the if statement tests whether password is equal to 123456. If so, it prints Login succeeded;<br>
<br>
if not it prints Error Login.<br>
<br>
<b>The switch... case Statement</b><br>
<br>
We use switch... case statement to test an expression, determine which of several cases it matches, and execute the corresponding code. Here's the syntax:<br>
<br>
char chr = 'B';<br>
<br>
switch (chr)<br>
<br>
{<br>
<br>
case 'A':<br>
<br>
// Do something.<br>
<br>
break;<br>
<br>
case 'B':<br>
<br>
// Do something.<br>
<br>
break;<br>
<br>
case 'C':<br>
<br>
// Do something.<br>
<br>
break;<br>
<br>
case 'D':<br>
<br>
// Do something.<br>
<br>
break;<br>
<br>
default:<br>
<br>
// Do something.<br>
<br>
break;<br>
<br>
}<br>
<br>
for the rest of this lesson, and many other csharp and vb.net tutorials, visit us at:<br>
<br>
<a target="_new" rel="nofollow" href="http://www.how2prog.com/">http://www.how2prog.com/</a>Wed, 29 May 2013 08:47:35 GMTHow2ProgRE: Learn Csharp Basics in 1 Hour - Csharp Tutorial For Beginnershttp://www.a1vbcode.com/vbforums/FindPost31973.aspxThanks for sharing such an informative post. These basic things are very important for beginners.Fri, 24 May 2013 01:12:53 GMTannaharris