A Quick Peek To C# Language
A Quick Peek To C# Language
a-peek-to-csharp-language
A quick peek to C# language
C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft. It's commonly
used for building applications ranging from web, desktop, and mobile apps to game development.
1. Setting Up
To get started with C#, you'll need:
Visual Studio (IDE): Download and install Visual Studio Community Edition.
.NET SDK: It comes with Visual Studio, but you can also download it separately.
2. Hello World
The basic "Hello, World!" program in C# looks like this:
using System;
namespace HelloWorldApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
using System : This imports the System namespace, which contains basic functionality like Console .
Main is the entry point of a C# program.
Console.WriteLine prints text to the console.
Example:
1/4
a-peek-to-csharp-language
int age = 30;
double height = 5.9;
string name = "Alice";
bool isStudent = true;
5. Loops
C# provides several loop constructs, including for , while , and foreach .
for loop:
while loop:
int count = 0;
while (count < 5)
{
Console.WriteLine($"Count: {count}");
count++;
}
foreach loop:
2/4
a-peek-to-csharp-language
Console.WriteLine(name);
}
6. Functions (Methods)
Functions in C# help break your code into reusable blocks.
Defining a class:
class Person
{
public string Name { get; set; }
public int Age { get; set; }
Creating an object:
3/4
a-peek-to-csharp-language
Arrays:
int[] numbers = { 1, 2, 3, 4, 5 };
Lists:
9. Exception Handling
Use try-catch blocks to handle runtime errors gracefully.
try
{
int number = int.Parse("ABC"); // This will throw an exception
}
catch (FormatException ex)
{
Console.WriteLine("Input string was not in a correct format.");
}
10. Conclusion
This is a brief introduction to C# basics. From here, you can explore more advanced topics like:
For more detailed learning, check out official C# documentation and tutorials from Microsoft.
Happy coding!
Source
https://maduranga.com/a-peek-to-csharp-language
4/4