
Create a project in Visual Studio by selecting new project, choosing a console app, naming the project, and running the main method in the program that shows Hello world.
Create and link a new class, define a public void method, print to the console, and call it from the main method via an object instance.
Learn how to declare a string array, initialize with names, access elements using zero-based indices, check the array length, and print each value with a for loop.
Here I provide the code for the simple basics in C# in a downloadable zip file:
Topics covered:
Simple Print to the Console,
Use an integer variable
Use an if-else statement, with a few variations
Use a ternary if statement
Generate a random number
Get an integer value from the end-user via the console
Get an One Letter from the end-user via the console
Use a string value in an if-statement
Use a string value in a switch-case
Standard for loop (i.e. count the iterations )
Enhanced for loop (i.e. simply loop till over all letters on a word for any length of word)
While loop
Data types
Exercise: Win the Lottery!
Exercise: Enter the password 3 times
Exercise: Is the password valid?
Here is a zip file with examples for using arrays
In this zip file, you will get sample code to use :
List
C# lists are a popular choice among developers for managing data collections. Their flexibility and dynamic nature make them highly effective for storing and manipulating data across a wide range of applications.
The use indexes and have no fixed size, but can grow and shrink in size.
LinkedList
ArrayList
Queues
In C#, a queue is a First-In, First-Out (FIFO) collection — meaning the first item added is the first one to be removed. It works like a real-world queue (e.g., a line at a store): Enqueue adds an item to the end, Dequeue removes the item from the front.
HashSet
In C#, a HashSet<T> is a collection that stores unique elements only, meaning it automatically prevents duplicates.
Dictionaries
In C#, a Dictionary<TKey, TValue> is a collection that stores key-value pairs — similar to a map or hash table in other languages. Each key must be unique, and is used to quickly retrieve its associated value.
Generics
In C#, a generic data structure is a type-safe and reusable collection or class that can work with any data type without knowing the exact type in advance.
What Does "Generic" Mean? A generic allows you to define a class, method, or data structure with a placeholder for the data type, which is specified when it's used. Think of it like a template that works with int, string, float, custom objects — whatever you pass in.
“At Microsoft, we use a variety of programming languages to develop and deliver products and services to our customers. C# continues to be a highly valued language for Microsoft, and we are committed to its ongoing growth and development,” a Microsoft spokesperson told "The New Stack", 16 Feb 2024.
Look out for Zipped Code Source Files!
In this course, we have the following learning objectives:
1) Create a c# project
2) The basics clearly explained
3) The Basics in a Zip File: Download worked examples of the basics to use when you need them.
4) Arrays: Videos as well as Zip file to download
5) Recursion
Why is it such a good idea to learn C#?
1. C# is Simple, Readable, and Easy to Use
C# excels in readability and simplicity, drawing from C, C++, and Java. It introduces value types, properties, and events, and avoids raw pointers and multiple inheritance. The language is very is easy to learn.
2. C# Enhances Developer Productivity
C# has strong typing support and powerful tools like Visual Studio and R#, which enhance the developer experience and make it quick and easy to code.
3. C# Supports Multiple Programming Paradigms
Originally object-oriented, C# now supports imperative, declarative, generic, and functional styles. Generics enable type-safe data structures and algorithms. LINQ introduces functional programming. Features like lambda expressions, extension methods, and pattern matching enhance C#'s functionality and readability
4. C# is a Versatile General-Purpose Language
C# is highly flexible, supporting the development of a wide range of applications, from console and desktop to web, mobile, AI, cloud, games, and IoT.
5. C# Runs on a Solid .NET Runtime
C# is integrated into the .NET ecosystem, benefiting from the .NET’s features like memory management, JIT compilation, and security. The transition from .NET Core to .NET 6 unified the platform, offering cross-platform capabilities.
6. C# is cross-platform.
Originally limited to Windows, C# now runs on multiple operating systems, including Linux and Mac, thanks to .NET. .NET MAUI extends C#'s capabilities to mobile platforms like Android and iOS, broadening its usability across different environments.
7. C# is Mature, Popular, and Actively Developed
With 24 years of continuous evolution, C# is a mature language. It ranks among the top five most popular programming languages, with .NET being a highly appreciated development framework. Frequent updates and community-driven development keep C# at the forefront.
8. C# is Open-Source, Led by Microsoft
C# is developed openly on GitHub, inviting community feedback and contributions. Microsoft oversees its development.
9. C# Has a Vibrant Community
The C# and .NET communities are active and supportive, with numerous local and online events. The .NET Foundation backs community initiatives.
10. C# is well-documented.
C# offers extensive documentation, with resources like Microsoft Learn and the official C# specification providing comprehensive learning materials.
11. C# Embeds Design Patterns and Best Practices
C# incorporates many design patterns directly into the language, facilitating their correct and elegant implementation.
12. C# Leverages Extensive Libraries
The .NET framework's Base Class Library offers a vast collection of types for common tasks, providing reusable components and frameworks.
13. C# Can Run Fast
While not initially designed for performance, C# has introduced features to optimize speed and memory usage. The JIT compiler, along with performance-enhancing features like structs and Span<T>, allows C# to run efficiently. Native AOT enables faster start-up times and smaller memory footprints.
14. C# Runs in the Browser
Blazor enables C# for client-side web applications using WebAssembly, running C# code natively in browsers without plugins, enhancing C#'s versatility in web development.
15. C# Developers Are in High Demand
C# skills are highly sought after, with numerous job opportunities and competitive salaries worldwide..
Conclusion
C# is a well-designed, productive, and versatile language in high demand. Learning C# in 2024 can be a strategic career move, offering opportunities in diverse application domains and a supportive community for continuous growth.