0% found this document useful (0 votes)
15 views

01 Type Casting, Variable Type, Class Object, Constructor

Uploaded by

Tanjim Ibrahim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

01 Type Casting, Variable Type, Class Object, Constructor

Uploaded by

Tanjim Ibrahim
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 99

C# Basics

Course Code: CSC 2210 Course Title: Object Oriented Programming 2

Dept. of Computer Science


Faculty of Science and Technology

Lecturer No: 02 Week No: 02 Semester: Summer 2019-2020


Lecturer:
Topics

• C# Data Types
• Type Casting
• The keywords readonly and const
• Structures
• Enumeration
• String
• Use of params, ref, out
• Understand the concept of Class and Object
• Learn about constructors
• Variable Types
THE C# BASICS
Pass Value by
Reference
Pass Value by
Reference
#NB:
Namespace
can have
multiple class
inside
The first and second elements are the instance of class
Geeks1 and class Geeks2. The third element is a string and
the fourth element is a double value and the fifth element is
a null value. Here, string str = obj[j] as string; we are
using as operator to cast the object array as a string and
store result into the string str. After that, check for the
resultant value. If it is null then print the “element is not a
string” and if not null, then print the string.
Write a code with “is” operator to check whether type is correct
Write a code with struct so that we can save passport
Information such as: ID, Name, DOB, country etc.
Months.April will print 3
Class & Object
protected string name = "Sheeran";

Error CS0122 'Student.name' is inaccessible due to its protection level


Error CS0122 'Student.print()' is inaccessible due to its protection level
if you make a class member static, you can access it
without object.
class geeks {
static geeks() {
Console.WriteLine("Static Constructor");
}
public geeks(int i) {
Console.WriteLine("Instance Constructor " + i);
}
public string geeks_detail(string name, int id) {
return "Name:" + name + " id:" + id;
}
public static void Main() {
geeks obj = new geeks(1);
Console.WriteLine(obj.geeks_detail("GFG", 1));
geeks obj1 = new geeks(2);
Console.WriteLine(obj1.geeks_detail("GeeksforGeeks", 2));
}
}
}
namespace copyConstructorExample {
class Geeks {
private string month;
private int year;
public Geeks(Geeks s) {
month = s.month;
year = s.year;
}
public Geeks(string month, int year) {
this.month = month;
this.year = year;
}
public string Details{
get{
return "Month: " + month.ToString() +
"\nYear: " + year.ToString();
}
}
public static void Main() {
Geeks g1 = new Geeks("June", 2018);
Geeks g2 = new Geeks(g1);
Console.WriteLine(g2.Details);
}
}
}
A signature makes a method look unique. The method name and
the type and order of parameters all contribute to the uniqueness
of signatures. Signatures enable the overloading mechanism of
members in classes, structs, and interfaces.
Garbage collection (GC) is a memory recovery feature built into
programming languages such as C# and Java. A GC-enabled programming
language includes one or more garbage collectors (GC engines) that
automatically free up memory space that has been allocated to objects no
longer needed by the program.
Thank You
Books

• C# 4.0 The Complete Reference; Herbert Schildt; McGraw-Hill Osborne Media; 2010
• Head First C# by Andrew Stellman
• Fundamentals of Computer Programming with CSharp – Nakov v2013
References

MSDN Library; URL: http://msdn.microsoft.com/library

C# Language Specification; URL: http://download.microsoft.com/download/0/B/D/0BDA894F-


2CCD-4C2C-B5A7-4EB1171962E5/CSharp%20Language%20Specixfication.doc

C# 4.0 The Complete Reference; Herbert Schildt; McGraw-Hill Osborne Media; 2010

You might also like