-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
163 lines (136 loc) · 6.72 KB
/
Program.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
namespace First_Script
{
internal class Program
{
static void Main(string[] args)
{
///////////// Types \\\\\\\\\\\\\\
// string --> AmIrReZa |
// char --> A |
// int --> 1,2,3,4,5,6,7,8,9 |
// float --> 1,2,3,4,5,6,7,8,9 |
// double --> 1.1, 2.2, 3.3, ... |
// decimal --> 1,2,3,4,5,6,7,8,9 |
// bool --> true or false |
////////////////\\\\\\\\\\\\\\\\\\
////////////// String \\\\\\\\\\\\\\
string example = "Example"; // --> Defult string
Console.WriteLine(example.Length); // --> Get count --> Output : 7
Console.WriteLine(example.ToUpper()); // --> Upper case --> Output : EXAMPLE
Console.WriteLine(example.ToLower()); // --> Lower case --> Output : example
Console.WriteLine(example.Contains("Example")); // --> Find string --> Output : True
Console.WriteLine(example[0]); // --> Index of string --> Output : E
Console.WriteLine(example.IndexOf("E")); // --> Find index --> Output : 0
Console.WriteLine(example.Substring(4)); // --> Cut string --> Output : ple
Console.WriteLine(example.Substring(4, 3)); // --> Cut string by numer --> Output : ple
////////////// Numbers \\\\\\\\\\\\\\
Console.WriteLine(5 + 8); // --> Addition --> Output : 13
Console.WriteLine(5 - 8); // --> Subtraction --> Output : -3
Console.WriteLine(5 / 8); // --> Division --> Output : 0
Console.WriteLine(5 * 8); // --> Multiplication --> Output : 40
Console.WriteLine(5 % 8); // --> Percentage --> Output : 5
////////////// Input \\\\\\\\\\\\\\
Console.WriteLine("Hi,");
Console.Write("Enter your name : ");
string name = Console.ReadLine(); // --> Get input (Name)
Console.WriteLine("Hello " + name); // --> Say Hi
Console.Write("Enter your age : ");
string age = Console.ReadLine(); // --> Get input (Age)
Console.WriteLine("Oh your are " + age); // --> Say age of input
Console.ReadLine();
////////////// try & catch & finally \\\\\\\\\\\\\\
try {
Console.Write("Don't Enter Number :");
int user_text = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(user_text); // --> Print your number --> Output : your text
} catch (Exception error) {
Console.WriteLine(error.Message); // --> Print error message --> Output : Input string was not in a correct format.
} finally {
Console.WriteLine("Your Answer Sent !");
}
////////////// Arrays \\\\\\\\\\\\\\
int[] numbers = { 1, 2, 3, 4, 5, 6, 7 }; // --> Tables
// 0 1 2 3 4 5 6
Console.WriteLine(numbers[6]); // Output : 7
int[,] new_numbers = { // 2D
{1, 2},
{3, 4},
{4, 5},
};
Console.WriteLine(new_numbers[2, 1]); // Output : 3
////////////// Run Functions \\\\\\\\\\\\\\
SayInformation(name, Convert.ToInt16(age)); // --> Age need to convert because (In past is string, but now we need int)
int F_Cube = Cube(5);
Console.WriteLine(F_Cube); // --> Cube Of 5 --> Output : 125
////////////// if \\\\\\\\\\\\\\
bool status = true;
if (status) {
Console.WriteLine("Status is true !");
} else {
Console.WriteLine("Status is false !");
}
///////////// States \\\\\\\\\\\\\
// && --> and |
// || --> or |
// ! --> not |
////////////////\\\\\\\\\\\\\\\\\\
////////////// Switch \\\\\\\\\\\\\\
string get_number = GetNumber(1);
Console.WriteLine(get_number); // --> Choose number text --> Output : first number !
////////////// While \\\\\\\\\\\\\\
int index = 6;
do
{
Console.WriteLine(index); // --> Check then while --> Output : 6
index++;
} while (index <= 5);
////////////// For \\\\\\\\\\\\\\
int[] numtables = { 4, 8, 9, 78, 65, 35, 60, 83 };
for(int i = 0; i <= numtables.Length; i++) // --> Print numbers
{
Console.WriteLine(numtables[i]);
}
}
////////////// Functions \\\\\\\\\\\\\\
/// <summary>
/// This is for information
/// </summary>
/// <param name="name"></param>
/// <param name="age"></param>
static void SayInformation(string name, int age) // --> Function Say Information
{
Console.WriteLine("\nName: "+ name +"\nAge: "+ age +"\nThis Line Write With Function !");
}
/// <summary>
/// This is for cube
/// </summary>
/// <param name="number"></param>
static int Cube(int number) // --> Function To Cube Number
{
int result = number * number * number;
return result;
}
/// <summary>
/// This is for get number text
/// </summary>
/// <param name="number"></param>
static string GetNumber(int number) // --> Function To Get Number Text
{
string result;
switch (number)
{
case 1:
result = "first number !";
break;
case 2:
result = "secend number !";
break;
default:
result = "wrong !";
break;
}
return result;
}
}
}