SlideShare a Scribd company logo
Namespace and Classes
Eng Teong Cheah
Microsoft MVP Windows Development
Xamarin: the complete mobile lifecycle solution
Namespace
Namespace
Namespace is a logical grouping of classes. These are used to organize the program
and also provide assistance in avoiding name clashes.
Example: System.Console.WriteLine();
Here system is a namespace. Namespace are used to group many classes together.
namespace System
{
Static class Console
{
}
}
Classes
Classes
A class consists of data and behavior. Class variables shows it data and methods and
events shows its behavior.
Class can contain combination of any of the following fields:
- Constructor
- Fields
- Methods
- Events
- Delegates
- Properties
- Destuctors
Example: See a simplified example of a class
class operation
{
//data members
int a;
int b;
//constructor
operation(int i, int j)
{
this.a = i;
this.b = j;
}
//function members
public int sum()
{
return this.a + this.b;
}
//destructor
~operation()
{
GC.Collect();
}
}
Class modifiers
Class modifiers modify the visibility of a class. Modifiers denote access or behavior
Class which is not nested have two access modifiers
Internal
An internal class is accessible only within files in the same assembly.
Public
public class has no restrictions on its accessibility.
Nested class can have two more accessibility private and protected. Nested class
behaves like any other member (field or methods). See example below for protected
class:
. internal class printer
{
protected void print()
{
Console.WriteLine("everything is printed");
}
}
Build this class as project type class library. Add new project and add code below add
reference to above build dll.
class program
{
public static void Main()
{
printclass.printer pr = new printclass.printer();
}
}
You will get following error message Error 1 ‘printclass.printer’ is inaccessible due to its
protection level. If we make printer class as public then we won’t get this error
message.
Abstract class
A class that cannot be instantiated and cannot be sealed but can inherited, contains
some methods which are only declared but not implemented is called Abstract Class.
Abstract class is generally used for keeping complex code in one base class and
derived class to be fairly simple. Example:
public abstract class printer
{
public abstract void print();
public void printall(string text)
{
Console.WriteLine(text);
}
}
Above class have two function on contains only body and other is fully implemented.
Sealed class
Sealed class cannot be inherited. Sealed class is used to prevent accidental inheritance.
Sting is a sealed class by Microsoft. Example:
sealed class printer
{
public void printall(string text)
{
Console.WriteLine(text);
}
}
Any class deriving from above type will lead to an error. New keyword is use only with
nested classes, new indicates that the class hides an inherited member of the same
name.
Demo
Get Started Today
Xamarin.com
•Website:
• http://techoschool.com/
•Get Started:
• http://xamarin.com
Reference

More Related Content

PDF
Xamarin: C# Methods
PDF
Xamarin: Inheritance and Polymorphism
PPTX
Exception Handling in C#
PPTX
Access Modifiers in C# ,Inheritance and Encapsulation
PPTX
Java abstract class & abstract methods
PPTX
Java interface
PPTX
java interface and packages
PPT
Java interfaces
Xamarin: C# Methods
Xamarin: Inheritance and Polymorphism
Exception Handling in C#
Access Modifiers in C# ,Inheritance and Encapsulation
Java abstract class & abstract methods
Java interface
java interface and packages
Java interfaces

What's hot (20)

PPTX
Interface in java ,multiple inheritance in java, interface implementation
PPT
Java interface
PPTX
Abstract class in c++
PPTX
PPTX
Abstract Class Presentation
PPTX
Polymorphism presentation in java
ODP
OOP java
PPTX
Polymorphism in java
PPTX
Classes and Objects in C#
DOCX
Uta005
PPTX
C# Types of classes
PPSX
Seminar on java
PPT
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
PPTX
encapsulation, inheritance, overriding, overloading
PPT
Chapter 9 Interface
PDF
Chapter23 friend-function-friend-class
PPTX
oops concept in java | object oriented programming in java
PPTX
Object oriented programming in java
PPTX
Structure of java program diff c- cpp and java
PPT
البرمجة الهدفية بلغة جافا - الوراثة
Interface in java ,multiple inheritance in java, interface implementation
Java interface
Abstract class in c++
Abstract Class Presentation
Polymorphism presentation in java
OOP java
Polymorphism in java
Classes and Objects in C#
Uta005
C# Types of classes
Seminar on java
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
encapsulation, inheritance, overriding, overloading
Chapter 9 Interface
Chapter23 friend-function-friend-class
oops concept in java | object oriented programming in java
Object oriented programming in java
Structure of java program diff c- cpp and java
البرمجة الهدفية بلغة جافا - الوراثة
Ad

Similar to Xamarin: Namespace and Classes (20)

DOCX
Introduction to object oriented programming concepts
PPTX
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
PPTX
Object Oriented Programming with C#
PPTX
PDF
OOPs difference faqs-3
PPTX
type of class in c#
PPT
20. Object-Oriented Programming Fundamental Principles
PPT
Constructor
PPTX
PPTX
Abstract class and Interface
PPTX
Better Understanding OOP using C#
PPTX
CSharp presentation and software developement
PPTX
Abstraction1
PPT
Advanced c#
PDF
Object-oriented programming (OOP) with Complete understanding modules
PPTX
C# overview part 2
PPTX
Quick Interview Preparation for C# All Concepts
PPTX
5. c sharp language overview part ii
PPTX
Unusual C# - OOP
Introduction to object oriented programming concepts
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
Object Oriented Programming with C#
OOPs difference faqs-3
type of class in c#
20. Object-Oriented Programming Fundamental Principles
Constructor
Abstract class and Interface
Better Understanding OOP using C#
CSharp presentation and software developement
Abstraction1
Advanced c#
Object-oriented programming (OOP) with Complete understanding modules
C# overview part 2
Quick Interview Preparation for C# All Concepts
5. c sharp language overview part ii
Unusual C# - OOP
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
PDF
Efficiently Removing Duplicates from a Sorted Array
PDF
Monitoring Models
PDF
Responsible Machine Learning
PDF
Training Optimal Models
PDF
Deploying Models
PDF
Machine Learning Workflows
PDF
Working with Compute
PDF
Working with Data
PDF
Experiments & TrainingModels
PDF
Automated Machine Learning
PDF
Getting Started with Azure Machine Learning
PDF
Hacking Containers - Container Storage
PDF
Hacking Containers - Looking at Cgroups
PDF
Hacking Containers - Linux Containers
PDF
Data Security - Storage Security
PDF
Application Security- App security
PDF
Application Security - Key Vault
PDF
Compute Security - Container Security
PDF
Compute Security - Host Security
Modern Cross-Platform Apps with .NET MAUI
Efficiently Removing Duplicates from a Sorted Array
Monitoring Models
Responsible Machine Learning
Training Optimal Models
Deploying Models
Machine Learning Workflows
Working with Compute
Working with Data
Experiments & TrainingModels
Automated Machine Learning
Getting Started with Azure Machine Learning
Hacking Containers - Container Storage
Hacking Containers - Looking at Cgroups
Hacking Containers - Linux Containers
Data Security - Storage Security
Application Security- App security
Application Security - Key Vault
Compute Security - Container Security
Compute Security - Host Security

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
sap open course for s4hana steps from ECC to s4
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.

Xamarin: Namespace and Classes

  • 1. Namespace and Classes Eng Teong Cheah Microsoft MVP Windows Development
  • 2. Xamarin: the complete mobile lifecycle solution
  • 4. Namespace Namespace is a logical grouping of classes. These are used to organize the program and also provide assistance in avoiding name clashes. Example: System.Console.WriteLine(); Here system is a namespace. Namespace are used to group many classes together. namespace System { Static class Console { } }
  • 6. Classes A class consists of data and behavior. Class variables shows it data and methods and events shows its behavior. Class can contain combination of any of the following fields: - Constructor - Fields - Methods - Events - Delegates - Properties - Destuctors
  • 7. Example: See a simplified example of a class class operation { //data members int a; int b; //constructor operation(int i, int j) { this.a = i; this.b = j; } //function members public int sum() { return this.a + this.b; } //destructor ~operation() { GC.Collect(); } }
  • 8. Class modifiers Class modifiers modify the visibility of a class. Modifiers denote access or behavior Class which is not nested have two access modifiers Internal An internal class is accessible only within files in the same assembly.
  • 9. Public public class has no restrictions on its accessibility. Nested class can have two more accessibility private and protected. Nested class behaves like any other member (field or methods). See example below for protected class: . internal class printer { protected void print() { Console.WriteLine("everything is printed"); } }
  • 10. Build this class as project type class library. Add new project and add code below add reference to above build dll. class program { public static void Main() { printclass.printer pr = new printclass.printer(); } } You will get following error message Error 1 ‘printclass.printer’ is inaccessible due to its protection level. If we make printer class as public then we won’t get this error message.
  • 11. Abstract class A class that cannot be instantiated and cannot be sealed but can inherited, contains some methods which are only declared but not implemented is called Abstract Class. Abstract class is generally used for keeping complex code in one base class and derived class to be fairly simple. Example: public abstract class printer { public abstract void print(); public void printall(string text) { Console.WriteLine(text); } } Above class have two function on contains only body and other is fully implemented.
  • 12. Sealed class Sealed class cannot be inherited. Sealed class is used to prevent accidental inheritance. Sting is a sealed class by Microsoft. Example: sealed class printer { public void printall(string text) { Console.WriteLine(text); } } Any class deriving from above type will lead to an error. New keyword is use only with nested classes, new indicates that the class hides an inherited member of the same name.
  • 13. Demo