Professional Documents
Culture Documents
Moar Stuffs
Moar Stuffs
Let's delve a bit deeper into some key concepts and syntax in C#:
1. **Variables and Data Types**: In C#, variables are used to store data. Before
using a variable, you need to declare its data type. Common data types in C#
include integers (`int`), floating-point numbers (`float`, `double`), strings
(`string`), booleans (`bool`), and more. Here's an example:
```csharp
int age = 25;
float height = 5.9f;
string name = "John Doe";
bool isStudent = true;
```
2. **Control Flow Statements**: Control flow statements are used to control the
flow of execution in a program. Common control flow statements in C# include `if`
statements, `switch` statements, `for` loops, `while` loops, and `foreach` loops.
Here's an example of an `if` statement:
```csharp
int num = 10;
if (num > 0) {
Console.WriteLine("The number is positive.");
} else if (num < 0) {
Console.WriteLine("The number is negative.");
} else {
Console.WriteLine("The number is zero.");
}
```
```csharp
int Add(int a, int b) {
return a + b;
}
```
```csharp
class Person {
public string Name;
public int Age;
```csharp
int[] numbers = { 1, 2, 3, 4, 5 };
Console.WriteLine(numbers[0]); // Output: 1
```
These are just a few fundamental concepts in C#. As you continue your learning
journey, you'll encounter more advanced topics like inheritance, polymorphism,
interfaces, exception handling, and more. Practice is key, so make sure to write
plenty of code and experiment with different concepts to solidify your
understanding.