Want to create interactive content? It’s easy in Genially!
Getting to Know C#
Philip Powichroski
Created on March 16, 2025
LMC 3403 Project
Start designing with a free template
Discover more than 1500 professional designs like these:
Transcript
Getting to Know C#
understand the basics of how to program and use C# in this ~1 hour tutorial
What is C#
C# is a modern, object-oriented programming language developed by Microsoft in 2000 that runs of the .NET Framework. It was designed to work similarly to java to allow for an easier adoptation for people transtioning away from C++ and Java.
+ info
Hello World!
Lets start with some starter code then explain it
// C# Hello World Programusing System; class HelloWorldProgram { // Main Method static void Main(string[] args) { // "printing Hello World" Console.WriteLine("Hello, World!"); } }
+ info
17
Index
5. Casting
1. Intro
2. Variables
6. Conditionals
7. Loops
3. Data Types
8. Arrays
4. Params
Intro
the .NET framework
It is a software development framework developed by microsoft. The framework supports multiple programming languages, such as C#, F#, and VB.NET, and supports a range of application types, including desktop, web, mobile, cloud, and gaming applications. The modern framework is cross-platform compatible with both windows and linux operating systems.
+ Fun Fact!
Variables
Varaibles are used to hold data during program executions
There are two ways to declare variables in C#// Method 1 type variable_name = value; // Method 2 type variable_names; Rules in C# -They can contain all alphanumeric characters including "-" -They Cannot start with a digit -the name cannot be a keyword like "int" or "float"
+ Vars
Data Types
There are 3 main categories
- Value Data Types
- Directly store value in memory
- Typically for numbers, chars, or booleans
- fixed memory size
- Reference Data Types
- contain memory addresses to certain variable
- commonly used for strings or objects
- Pointer Data Types
- Contain memory address of varaible value. Common with C programming
+ Pointers
Quiz Checkpoint
We will now take a quick quiz on what you have learned so far
Quiz #1
Quiz #1
Params
Params are incredibly useful in C#
It is used as a parameter which can take the variable number of arguments of specific data type. It is useful for flexibility when the number of arguments is unknown. Only one Param keyword is allowed per method. Params must always be the last parameter in a function decleration. If no argument are passed it will be treated as an empty array. This allws C# to simplify method overloading which is useful on OOP.
+ Example
Casting allows us to assign the data type of one object to another
Casting
When able, C# will automatically cast. For example, casting an int as a float. This is known as implicit or automatic type conversion. Explicit casting is done when objects are not directly compatible. This can follow the list below. But also works when casting objects as their parent class.double d = 765.12; // Explicit Type Casting // larger data into smaller data type int i = (int)d;
+ Explicit Casting
Conditionals
There are 2 types of conditionals
- If-Else Statements
- if (condition) {//code to be executed}
- else {//code to be executed}
- Switch statements
- Switch(expression or varaible){
+ Differences
Loops
2 main Types of Loops
while loopA while loop syntax is similar to most programming langauges: while(boolean condition){ //executing statements }for loop similar to a while loop, the only thing that changes is the syntax. for(loop varaible initialization; testing condition; increment/decrement amount){} EX: for(int i = 0; i < 10; i++){}
+ BEWARE
Arrays allow you to contain multiple variables at once
Arrays
An array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. to access each space you use its index. The first element has the index of 0 then 1 etc. To declare an array in C#:<Data Type>[ ] <Name_Array> - <data Type> defines type of elements i array - [] defines the size of the array - <Name_Array> is the name
+ Initializing
Quiz #2
Quiz #2
Thank you for learning
I hope this tutorial helped you learn how to program in C#
More Resources
https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/overview
Here is the official C# documentation for more information
Compatible Explicit castings
Quick History
The .NET framework was the third iteration by microsoft starting with OLE Technology followed by COM technology and later finishing with >NET tech.
Initializing an array
type [ ] < Name_Array > = new < datatype > [size]; Initializing after declaration: string[] str1; str1 = new string[5]{ “Element 1”, “Element 2”, “Element 3”, “Element 4”, “Element 5” };
What is OOP
Object-Oriented Programming (OOP) is a paradigm that organizes software design around objects and their interactions, focusing on creating reusable code. Key principles of OOP include inheritance, polymorphism, and encapsulation By using these principles, developers can create more modular, maintainable, and scalable software systems.
Explained!
Using is used to import a library, or set of classes, in this case we are importing the system library.static void Main(string[] args) is the main method. This allows the code to be executable and is what runs when the user clicks run Console.WriteLine outputs anything in the parentheses to a console
Key Differences
One of the primary differences is that an if statement can exist without an acompanying else statement. This can be useful if in a program you want to check to see if a certain value is correct then to branch off. Switch statements are best used if one variable can have many outcomes and you want a difference scenario for each case
WARNING
One of the biggest things to watch out for with while loops is the risk of ending up in an infinite loop. A while loop should always have a safegaurd or garuntee that it will eventually exit the loop. This is often done by creating a counter and incrmenting the counter. If the counter limit is reached you should break out of the loop
vars
The simplest way to refer to a variable is by declaring it as a var. This allows it to be cast to anything and prevents compile time errors but does leave space for more runtime errors
Here all that is highlighted are the params
public static int Add(params int[] ListNumbers) { int total = 0; // foreach loop foreach(int i in ListNumbers) { total += i; } return total; }
Pointers
To access pointers an "&" is used as the address operator which determines the address of a value. The "*" operator is the inderection operator, it finds the value of an address.