Skip to main content

C# in Action - Building Robust and Scalable Applications

C# in Action - Building Robust and Scalable Applications

1. Introduction to C#

C# (pronounced “C-sharp”) is a modern, object-oriented language developed by Microsoft. It’s widely used for desktop applications, web apps, and game development with Unity.

2. Setting Up Environment

To write and run C# programs, install:

using System;

class Program {
  static void Main() {
    Console.WriteLine("Hello, C#!");
  }
}

3. Basic Syntax

Each C# program starts with a Main() method.

4. Variables and Data Types

int age = 25;
string name = "Alice";
double price = 9.99;
bool isOnline = true;

5. Conditionals and Loops

for (int i = 1; i <= 5; i++) {
  Console.WriteLine(i);
}

if (age > 18) {
  Console.WriteLine("Adult");
}

6. Methods

static int Add(int a, int b) {
  return a + b;
}

7. Object-Oriented Programming

class Person {
  public string Name;
  public void Greet() {
    Console.WriteLine($"Hello, {Name}!");
  }
}

class Program {
  static void Main() {
    Person p = new Person();
    p.Name = "John";
    p.Greet();
  }
}

8. Best Practices

  • Follow PascalCase for class names and methods.
  • Use meaningful variable names.
  • Keep methods short and focused.

9. Mini Project — Simple Calculator

using System;

class Calculator {
  static void Main() {
    Console.Write("Enter first number: ");
    double a = Convert.ToDouble(Console.ReadLine());
    Console.Write("Enter operator (+, -, *, /): ");
    char op = Console.ReadLine()[0];
    Console.Write("Enter second number: ");
    double b = Convert.ToDouble(Console.ReadLine());

    double result = 0;
    switch(op) {
      case '+': result = a + b; break;
      case '-': result = a - b; break;
      case '*': result = a * b; break;
      case '/': result = a / b; break;
      default: Console.WriteLine("Invalid operator."); return;
    }

    Console.WriteLine($"Result: {result}");
  }
}

10. Conclusion

C# is powerful, elegant, and versatile — ideal for building secure and scalable applications across platforms.

Comments

Popular posts from this blog

How Android came into Existence

Android is a Linux Based Working Framework developed by GOOGLE which gives a rich application System and helps in creating intelligent applications. The first android operating system was released to the mobile market in 2007 with a considerable lot of its variants named in Sequential request going from A-N and impending is O.                                                               ANDROID VERSION HISTORY Alpha – The first primary adaptation of Android working Framework by Google. It has fundamental usefulness with a straightforward program and other Google applications like Gmail, Guides and YouTube.   Beta - Later on with Android 1.1 few greater usefulness added, the Programming interface changes from level 1 in Android 1.0 to level 2. It upholds connection with MMS (Multimedia Messages...