Skip to main content

C#

Here's a cheat sheet summarizing some of the key concepts, syntax, and features of the C# programming language:

csharp
// C# Language Cheat Sheet // Comments: Single-line comment /* Multi-line comment */ // Data Types: int // Integer float // Floating-point number double // Double precision floating-point number char // Character bool // Boolean string // String decimal // Decimal number DateTime // Date and time var // Implicitly typed variable // Variables: int age = 25; // Variable declaration and initialization float pi = 3.14; char letter = 'A'; // Constants: const int MAX_VALUE = 100; // Constant declaration // Input and Output: Console.WriteLine("Hello, World!"); // Output to console int age = Convert.ToInt32(Console.ReadLine()); // Input from user // Arithmetic Operators: +, -, *, /, % // Addition, Subtraction, Multiplication, Division, Modulo // Relational Operators: ==, !=, >, <, >=, <= // Equal to, Not equal to, Greater than, Less than, Greater than or equal to, Less than or equal to // Logical Operators: && // Logical AND || // Logical OR ! // Logical NOT // Control Flow: if (condition) { // Code executed if condition is true } else if (condition2) { // Code executed if condition2 is true } else { // Code executed if no previous conditions are true } switch (variable) { case value1: // Code executed if variable is equal to value1 break; case value2: // Code executed if variable is equal to value2 break; default: // Code executed if no previous cases match } while (condition) { // Code executed repeatedly while condition is true } for (initialization; condition; increment/decrement) { // Code executed repeatedly until condition is false } // Functions: return_type function_name(parameter1, parameter2) { // Code executed by the function return value; // Optional return statement } // Classes and Objects: class MyClass { private int x; public void SetX(int value) { x = value; } public int GetX() { return x; } } MyClass obj = new MyClass(); // Object instantiation obj.SetX(5); // Accessing member functions int value = obj.GetX(); // Inheritance: class DerivedClass : BaseClass { // Derived class definition } // Interfaces: interface IMyInterface { void MyMethod(); } class MyClass : IMyInterface { public void MyMethod() { // Method implementation } } // Properties: public int MyProperty { get; set; } // Automatic property // Exception Handling: try { // Code that may throw an exception } catch (ExceptionType e) { // Code to handle the exception } finally { // Code that always executes, regardless of whether an exception is thrown } // Generics: class MyClass<T> { T MyMethod(T parameter) { // Method implementation return parameter; } } // LINQ (Language-Integrated Query): var result = from variable in collection where condition select variable; // Collections (e.g., Lists, Arrays, Dictionaries, etc.): List<int> numbers = new List<int>(); // List declaration int[] array = new int[5]; // Array declaration Dictionary<string, int> dict = new Dictionary<string, int>(); // Dictionary declaration

This cheat sheet covers some of the most commonly used features and syntax in the C# programming language. It serves as a handy reference for quick look-ups and reminders while programming in C#.

 

Comments

Popular posts from this blog

Tokens, Identifiers, Data Types, Sequence Control, Subprogram Control, Arrays, Structures, Union, String, Pointers, Functions, File Handling, Command Line Argumaents, Preprocessors in C with example

 Let's discuss each concept briefly and provide examples for better understanding: 1. Tokens: Tokens are the smallest building blocks in C programming. They include keywords, identifiers, constants, strings, operators, and punctuators. Example: ```c #include <stdio.h> int main() {     int num = 42;  // 'int', 'main', 'return', '42', '=', ';' are tokens     printf("Hello, World!");  // 'printf', '(', ')', 'Hello, World!', ';', are tokens     return 0;  // 'return', '0', ';' are tokens } ``` 2. Identifiers: Identifiers are names used to identify variables, functions, or other user-defined entities. Example: ```c int age = 30;  // 'age' is an identifier (variable name) void displayMessage() {  // 'displayMessage' is an identifier (function name)     // function body } ``` 3. Data Types: Data types define the type of data that can be stored in ...

Web Programming: HTML, DHTML, XML, Scripting, Java, Servlets, Applets

 Web programming encompasses various technologies and concepts used to develop web applications. Let's explore each of them in detail: 1. HTML (Hypertext Markup Language): HTML is the standard markup language used to create the structure and content of web pages. It uses tags to define elements like headings, paragraphs, images, links, forms, etc. Example: ```html <!DOCTYPE html> <html> <head>     <title>My Web Page</title> </head> <body>     <h1>Hello, World!</h1>     <p>This is a paragraph.</p>     <img src="image.jpg" alt="Image">     <a href="https://www.example.com">Visit Example</a> </body> </html> ``` 2. DHTML (Dynamic HTML): DHTML is a combination of HTML, CSS, and JavaScript that allows web pages to become more dynamic and interactive. Example (DHTML with JavaScript): ```html <!DOCTYPE html> <htm...

Object Oriented Programming: Class, Object, Instantiation, Inheritance, Encapsulation, Abstract Class, Polymorphism

 Object Oriented Programming: Class, Object, Instantiation, Inheritance, Encapsulation, Abstract Class, Polymorphism Object-Oriented Programming (OOP) is a programming paradigm that focuses on organizing code into objects, which are instances of classes. OOP encourages the use of concepts such as inheritance, encapsulation, and polymorphism to create reusable and maintainable code. Let's explore each of these concepts in detail: 1. Class: A class is a blueprint or template for creating objects. It defines the attributes (data members) and behaviors (member functions) that the objects of the class will have. Classes act as user-defined data types that encapsulate data and methods related to a specific entity or concept. Example: ```java class Person {     String name;     int age;     void introduce() {         System.out.println("Hi, I am " + name + " and I am " + age + " years old.");   ...