Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

- Fall 2021 -

Asst Prof. Essaid Meryam


Department of Robotics Engineering
C# DataTypes
•The type of a variable specifies the type of data that it will store and, thus,
determines the storage space allocated for the variable in the memory. The
compiler uses type information to make sure that all operations in your code
are type safe.

C# Divides Types into Two Sets


•Predefined / Primitive types that the language offers. Also called built-in
types.
•User-defined types that the programmer defines.

Categories of Types
•value types
•reference types
Categories of Types
C# Methods

•MyMethod() is the name of the method

•static means that the method belongs to the Program class and


not an object of the Program class.

•void means that this method does not have a return value.


C# If ... Else
C# supports the usual logical conditions from mathematics:
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
• Equal to a == b
• Not Equal to: a != b

You can use these conditions to perform different actions for different decisions.
C# has the following conditional statements:
• Use if to specify a block of code to be executed, if a specified condition is
true
• Use else to specify a block of code to be executed, if the same condition is
false
• Use else if to specify a new condition to test, if the first condition is false
• Use switch to specify many alternative blocks of code to be executed
C# For Loop
When you know exactly how many times you want to loop through a block of
code, use the for loop instead of a while loop:

Statement 1 is executed (one time) before the execution of the code block.

Statement 2 defines the condition for executing the code block.

Statement 3 is executed (every time) after the code block has been executed.
C# Math
The C# Math class has many methods that allows you to
perform mathematical tasks on numbers.

 Math.Max(x,y)  Math. Min(x,y)  Math. Sqrt(x)

The Math.Max(x,y) meth The Math.Min(x,y) The Math.Sqrt(x) method


od can be used to find method can be used to returns the square root
the highest value find the lowest value of of x
of x and y of x and y

 Math. Abs(x,y)  Math. Round(x,y)

The Math.Abs(x) method Math.Round() rounds a


returns the absolute number to the nearest
(positive) value of x whole number
C# Arrays

Index = 0 ~ size-1
C# OOP
class objects
Car Volvo
Audi
Toyota

public class BankAccount


{
public static int interestRate;
}

BankAccount custAccount = new BankAccount();

// Constructor
public BankAccount(string acctName, int
acctNumber)
{
accountName = acctName;
accountNumber = acctNumber;
}
C# OOP Modifier
public
Description
The code is accessible for all classes
private The code is only accessible within the same class
protected The code is accessible within the same class, or in a class that is
inherited from that class.
internal The code is only accessible within its own assembly, but not from
another assembly.

Note: By default, all members of a class are private if you


don't specify an access modifier:

• The meaning of Encapsulation, is to make sure that


"sensitive" data is hidden from users. To achieve this, you
must:
 declare fields/variables as private
 provide public get and set methods, through properties, to
access and update the value of a private field
C# Enum
An enum is a special "class" that represents a group of constants (unchangeable/read-only variables).
To create an enum, use the enum keyword (instead of class or interface), and separate the enum items
with a comma:

You can access enum items with the dot syntax:


GUI
 GUI (graphical user interface) is a system of interactive visual components for
computer software.

• Interface elements include but are not limited to:


 Input Controls: checkboxes, radio buttons, dropdown lists, list boxes, buttons, toggles,
text fields, date field
 Navigational Components: breadcrumb, slider, search field, pagination, slider, tags,
icons
 Informational Components: tooltips, icons, progress bar, notifications, message boxes,
modal windows
 Containers: accordion
Adding Controls to form
• Group Box
• Label Control
• Textbox
• List box
• Radio Button
• Checkbox
• Messagebox
• Tree Control
• Picture Box
Model in C#
 
𝑦=𝑎𝑥+𝑏
𝑦=2∙2+4=8
Adding Menus To Windows Forms In C#
Q&A

You might also like