C2-01-Introduction to CS Programming.pdf

Full Transcript

Advanced Game Design : Brgy. Paciano Rizal, Calamba City, Laguna 4027 | : (049) 834-1159 : www.perpetualdalta.edu.ph Calamba Campus Contents CS Overview What is C#? Setting-up the Environment Basic Structure of C# Program C# Variabl...

Advanced Game Design : Brgy. Paciano Rizal, Calamba City, Laguna 4027 | : (049) 834-1159 : www.perpetualdalta.edu.ph Calamba Campus Contents CS Overview What is C#? Setting-up the Environment Basic Structure of C# Program C# Variables and Data Types Control Structures C# as OOP Wrap-up Overview C# (pronounced "C-sharp") is a modern, object- oriented programming language developed by Microsoft. It's part of the.NET framework. It’s used for a variety of applications, from desktop software to web services and games. What is C#? C# is an object-oriented, high-level programming language. It was designed to be simple, modern, and powerful, and is part of the.NET framework. It is widely used for developing Windows applications, web applications, and games (particularly using the Unity game engine). Setting Up Your Environment The most common tool for C# development is Microsoft Visual Studio, which offers a comprehensive IDE (Integrated Development Environment) with features for coding, debugging, and testing. Download and Install Visual Studio Create a New Project: Open Visual Studio. Select "Create a new project." Choose "Console App (.NET Core)" or "Console App (.NET Framework)" for a simple console application. Click "Next." Basic Structure of a C# Program A simple C# program that prints "Hello, World!" to the console: using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); } } Basic Structure of a C# Program using System; is a directive that tells the compiler to use the System namespace, which includes fundamental classes like Console. class Program defines a class named Program. In C#, all code must be contained within a class. static void Main() is the entry point of the program. It’s where execution begins. static means this method belongs to the class itself, not to any object of the class. void means this method does not return a value. Console.WriteLine("Hello, World!"); prints the text to the console. Basic Concepts: Variables and Data Types Variables are used to store data. You declare a variable by specifying its type and name Basic Concepts: Control Flow Conditions Loops Basic Concepts: Control Flow Functions (Methods) Functions are blocks of code that perform a specific task and can return a value. Object-Oriented Programming (OOP) C# is an object-oriented language, meaning it focuses on objects and classes. Classes define blueprints for objects. class Person { public string Name { get; set; } public int Age { get; set; } public void Introduce() { Console.WriteLine($"Hi, I'm {Name} and I'm {Age} years old."); } } static void Main() { Person person = new Person(); person.Name = “Billy"; person.Age = 20; person.Introduce(); // Outputs: Hi, I'm Alice and I'm 30 years old. } Object-Oriented Programming (OOP) Console.WriteLine($"Hi, I'm {Name} and I'm {Age} years old."); In C#, the $ symbol is used to denote an interpolated string. This feature, introduced in C# 6.0, allows you to embed expressions directly within a string literal. The result of these expressions is evaluated and inserted into the string. $":The $ before the opening quote tells the compiler that the string is an interpolated string. {Name}: Within the curly braces {}, you can place any expression or variable. The expression is evaluated, and its result is inserted into the string at that position. {Age}: Similarly, {Age} will be replaced by the value of the Age variable. **String interpolation makes it easier to create strings that include variables or expressions without having to use concatenation or format specifiers. Wrap-Up Getting started with C# involves understanding its syntax and basic concepts, setting up your development environment, and writing simple programs to build your skills. The activities and examples provided are designed to give you hands-on experience and reinforce learning. As you continue practicing, you'll become more comfortable with C# and its features. Here are a few tips as you move forward: Practice Regularly: Write small programs and experiment with different features to solidify your understanding. Seek Resources: Utilize books, online courses, and documentation to deepen your knowledge. Engage with the Community: Join forums and coding communities to ask questions, share knowledge, and learn from others. References Microsoft Learn: Microsoft Learn provides tutorials and documentation on C# and.NET. C# Documentation: The C# Programming Guide offers in- depth information and examples. Online Courses: Websites like Pluralsight, Udemy, and Coursera offer courses on C#. Thank You! : Brgy. Paciano Rizal, Calamba City, Laguna 4027 | : (049) 834-1159 | : www.perpetualdalta.edu.ph Calamba Campus

Use Quizgecko on...
Browser
Browser