Why Teams call analytics are critical to your entire business
C Sharp Lecture Johan Franzen
1. The C# Language
Johan Franzén
C# – Overview
Panel 1 Panel 2
Object Oriented (similar to Java)
Appeared in 2001
.NET Platform (VB.NET, J#, Managed C++ and more)
Microsoft Windows
Linux and Mac OS X with the mono project
1
2. C# – Common Language Infrastructure
Panel 1 Panel 2
C# – Hello World
Panel 2
using System;
class Hello
{
static void Main() {
Console.WriteLine(quot;Hello
Console.WriteLine(quot;Hello worldquot;);
}
}
2
3. C# – Data types
int Panel 2
float
string
byte
bool
.
.
.
float fValue = 2.0f;
double dValue = 2.0;
bool bValue = 5 (incorrect)
C# – Value Types and Reference Types
Panel 1 Panel 2
Value Types Value Type
Point is a Struct
By Value (copy) Point p1 = new Point();
Point p2 = p1;
int, float, … , Point, Vector2 (structs)
(p2 is a copy of p1)
Reference Types
By Reference (reference)
Reference Type
Classes
Person is a Class
Person p1 = new Person();
Person();
Person p2 = p1;
(p2 points to the same
object as p1)
3
4. C# – Array & List
Array (fixed size)
int[]
int[] myArray = new int[10];
int[10];
myArray[2]
myArray[2] = 3;
List (can grow)
List<int>
List<int> myList = new List<int>();
List<int>();
myList.Add(3);
myList.Add(3);
int myValue = myList[0];
myList[0];
C# – Iteration
Standard for loop
o
for( t y st Cou tt;
myList.Count;
for(int i = 0; i < myList.Count; i++) {
)
Console.WriteLine(myList[
Console.WriteLine(myList[i]);
}
foreach loop
foreach(
foreach(int value in myList) {
myList)
Console.WriteLine( l )
Console.WriteLine(value);
C l W it Li (value);
}
4
5. C# – get/set methods
Java Panel 1
------------------------------------------------
class Person {
private int age;
public int getAge() { return age; }
getAge()
public void setAge(int value) {
setAge(
if(age
if(age >= 0)
age = value;
}
}
------------------------------------------------
Person p = new Person();
Person();
p.setAge(20);
p.setAge(20);
int age = p.getAge();
p.getAge();
C# – Properties
C# Panel 1 Panel 2
------------------------------------------------
class Person {
private int age;
public int Age {
get { return age; }
set {
if(age
if(age >= 0)
age = value;
value;
}
}
}
------------------------------------------------
Person p = new Person();
Person();
p.Age = 20;
int age = p.Age;
p.Age;
5