SlideShare a Scribd company logo
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
1 
C# for C++ Programmers
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
2 
How C# Looks
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
3 
using genericCar; 
namespace Toyota; 
{ 
public class Camry : Car 
{ 
private static Camry camry; 
private Brake brake; 
public void main() 
{ 
camry = new Camry(); 
camry.getBrake().ToString(); 
} 
public Camry() 
{ 
this.brake = new Brake(); 
} 
public override Brake getBrake() 
{ 
return this.brake; 
} 
} 
} 
C# Console Application Project
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
4 
using System.IO; 
namespace Toyota 
{ 
public class Brake 
{ 
string brakeName; 
public Brake() 
{ 
this.brakeName = “Brake 1”; 
} 
public override string ToString() 
{ 
System.Console.Out.Writeln(“I’m ” + this.brakeName); 
} 
} 
} 
Namespace GenericCar 
Class Car 
Public MustOverride Sub getBrake() 
End Class 
C# Class Library Project 
Vb.net Class Library Project
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
5 
Differences between C# and C++
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
6 
Pointers 
• Can be used in C# , but only in code blocks, methods, or classes 
marked with the unsafe keyword. 
• Primarily used for accessing Win32 functions that use pointers. 
class MyClass 
{ 
unsafe int *pX; 
unsafe int MethodThatUsesPointers() 
{ //can use pointers 
} 
int Method() 
{ 
unsafe 
{ //can use pointers 
} 
} 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
7 
References, Classes, and Structs 
• References 
– are used in C#, which are effectively opaque pointers that don’t 
allow the aspects of pointer functionality that can cause bugs. 
• Classes and structs 
– are different in C#: 
– structs are value types, stored on the stack, and cannot inherit, 
– classes always reference types stored on the managed heap 
and are always derivatives of System.Object.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
8 
Accessing native code 
• C# code can only access native code through PInvoke. 
class PInvoke 
{ 
[DllImport("user32.dll")] 
public static extern int MessageBoxA( int h, string m, string c, int type); 
public static int Main() 
{ 
return MessageBoxA(0, "Hello World!", "My Message Box", 0); 
} 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
9 
Destruction 
• Destruction 
– Same syntax as for C++, but don’t need to declare it as virtual 
and shouldn’t add an access modifier. 
– C# cannot guarantee when a destructor will be called – called by 
the garbage collector. 
– Can force cleanup: System.GC.Collect(); 
– For deterministic destruction, classes should implement 
IDisposable.Dispose() 
– C# supports special syntax that mimics C++ classes that are 
instantiated on the stack where the destructor is called when it 
goes out of scope: 
using (MyClassThatHasDestructor mc = new MyClassThatHasDestructor) 
{ 
//code that uses mc 
} // mc.Dispose() implicitly called when leaving block.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
10 
Miscellaneous 
• Binary PE format 
– C# compiler will only generate managed assemblies – no native 
code. 
• Operator Overloading 
– C# can overload operators, but not as many. Not commonly 
used. 
• Preprocessor 
– C# has preprocessor directives, similar to C++ but far fewer. No 
separate preprocessor – compiler does preprocessing. 
– C# doesn’t need #include – no need to declare compiler symbols 
used in code but not yet defined.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
11 
Miscellaneous 
• C# doesn’t require a semicolon after a class 
• C# doesn’t support class objects on the stack. 
• const only at compile time, readonly set once at 
runtime in constructor. 
• C# has no function pointers – delegates instead.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
12 
C# New Features
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
13 
Delegates 
delegate void AnOperation(int x); 
class AClass 
{ 
void AMethod(int i) 
{ 
System.Console.WriteLine(“Number is ” + i.ToString()); 
} 
static int Main(string[] args) 
{ 
AClass aClass = new AClass(); 
AnOperation anOperation = new AnOperation(AClass.AMethod); 
anOperation(4); 
} 
} 
stdio console output: 
Number is 4 
– When delegate returns a void, is a ‘multicast’ delegate and can represent more than one 
method. += and -= can be used to add and remove a method from a multicast delegate.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
14 
Events 
• An event source EventSourceClass declares an event 
with this special syntax: 
public delegate void EventClass(obj Sender, EventArgs e); 
public event EventClass SourceEvent; 
• Client event handlers must look like this: 
void MyEventCallback(object sender, EventArgs e) 
{ 
//handle event 
} 
• Client event handlers are added to an event source like 
this: 
EventSourceClass.SourceEvent += MyEventCallback; 
• An event source then invokes the event like this: 
SourceEvent(this, new EventArgs());
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
15 
Attributes and Properties 
• Attributes 
– meta info that can be accessed at runtime 
[WebMethod] 
public ShippingPreference[] GetShippingPreferences(ShoppingCart 
shoppingCart, CustomerInformation customerInformation) 
{ 
} 
• Properties 
class ContainsProperty 
{ 
private int age; 
public int Age 
{ 
get { return age;} 
set { age = value;} 
} 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
16 
Exceptions 
• Exceptions in C# support a finally block: 
try 
{ 
//normal execution path 
} 
catch (Exception ex) 
{ 
//execution jumps to here if Exception or derivative 
//is thrown in try block. 
} 
finally 
{ 
//ALWAYS executes, either after try or catch clause executes. 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
17 
Miscellaneous 
• Interfaces 
• Threading 
lock() statement (shortcut for System.Threading.Monitor) 
• Boxing 
– Value types are primitives. 
– Value types can be treated as objects 
– Even literal types can be treated as objects. 
string age = 42.ToString(); 
int i = 20; 
object o = i;
C++ features unsupported in C# 
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
18 
• No templates – generics instead (C++/CLI has both) 
• No multiple inheritance for base classes.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
19 
Configuration
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
20 
XML File Based 
• .NET assemblies use XML-based configuration 
files named ExecutableName.exe.config 
• Registry is not commonly used for .NET 
applications.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
21 
File Format 
• ExecutableName.exe.config looks like: 
<configuration> 
<system.runtime.remoting> 
<application> 
<channels> 
<channel ref="tcp" port="9091" /> 
</channels> 
</application> 
</system.runtime.remoting> 
<appSettings> 
<!-- SERVICE --> 
<!-- false will cause service to run as console application, true requires installing and running as a Windows service --> 
<add key = "Service.isService" value = "false" /> 
<add key = "Service.eventsourcestring" value = "CCLI Service" /> 
<add key = "Service.servicename" value = "CCLI Service" /> 
<add key = "ServiceAssemblyName" value = "Framework" /> 
<add key = "ServiceClassNameConsole" value = "StarPraise.Core.ConsoleBootstrapper" /> 
<add key = "ServiceClassNameService" value = "StarPraise.Core.ComponentController" /> 
<add key = "Service.strStarting" value = "Service starting..." /> 
<add key = "Service.strStopping" value = "Service Stopping..." /> 
<!-- Configuration to use DefaultLogger - writing straight to file. Only for testing - NOT FOR PRODUCTION USE. --> 
<add key = "Logger.loggerAssembly" value = "Framework" /> 
<add key = "Logger.loggerclassname" value = "StarPraise.Core.DefaultLogger" /> 
… 
</configuration>
Accessing Configuration Values 
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
22 
static protected Logger getInstance() 
{ 
if (Logger.loggerInstance == null) 
{ 
try 
{ 
ObjectHandle obj = Activator.CreateInstance( 
System.Configuration.ConfigurationManager.AppSettings[Logger.loggerAssembly], 
System.Configuration.ConfigurationManager.AppSettings[Logger.loggerclassname]); 
Logger.loggerInstance = (Logger) obj.Unwrap(); 
Logger.loggerInstance.Start(); 
} 
catch (Exception ex) 
{ 
throw new RuntimeException(ex.ToString(), new 
ComponentIdentity("Logger"), "getInstance"); 
} 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
23 
Application Types
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
24 
Types 
There are five primary application 
(‘executable’) projects in Visual Studio: 
• Console Applications 
• Services 
• Forms Applications 
• Web Applications 
• Web Services
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
25 
Form Applications 
• VS.NET creates Main and adds to the form 
application project. 
• Windows Message Pump is encapsulated 
entirely within classes contained in 
System.Windows. 
• System.Windows.Forms.Form is type 
automatically created by VS.NET for forms 
application projects.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
26 
Forms Applications 
using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 
namespace 
CompassPoint.ECommerce.OrderProcessingServ 
ices 
{ 
static class Program 
{ 
/// <summary> 
/// The main entry point for the 
application. 
/// </summary> 
[STAThread] 
static void Main() 
{ 
Application.EnableVisualStyles(); 
Application.SetCompatibleTextRenderingDefa 
ult(false); 
Application.Run(new 
OrderProcessingWebServiceTest()); 
} 
} 
} 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
namespace 
CompassPoint.ECommerce.OrderProcessingServices 
{ 
public partial class 
OrderProcessingWebServiceTest : Form 
{ 
public OrderProcessingWebServiceTest() 
{ 
InitializeComponent(); 
} 
} 
}
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
27 
Web Applications 
• They are hosted in IIS. 
• A variety of compile options from compile when accessed to pre-compile 
including partial compile in the creamy middle! 
• When webpage.aspx is accessed, 
– IIS delegates to the ASP.NET runtime which 
• creates a runtime object model for the page, 
• Reads the page 
• Returns all markup to IIS to return to browser except 
• Embedded runat=server marked code in the page which it 
runs in the runtime object model environment and returns the 
resulting markup.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
28 
Web Services 
• When a webservice.asmx is accessed, the 
same thing happens, but SOAP ‘method’ 
invocation requests are redirected to 
methods in the web service marked with a 
special attribute.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
29 
Web Services 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[ToolboxItem(false)] 
public class OrderProcessingService : System.Web.Services.WebService, 
IOrderManager 
{ 
[WebMethod] 
public ShippingPreference[] GetShippingPreferences(ShoppingCart 
shoppingCart, CustomerInformation customerInformation) 
{ 
….
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
30 
Web Application and Service 
Configuration 
• As for applications, configuration is stored in an 
XML file. 
• XML file is of same format as for other types of 
applications. 
• For both, the file is named web.config.
© 2007 Compass Point, Inc. 
9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  info@compass-point.net 
www.compass-point.net 
31 
Discussion
Ad

More Related Content

What's hot (20)

C++
C++C++
C++
Sunil OS
 
Collection v3
Collection v3Collection v3
Collection v3
Sunil OS
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
Java cheat sheet
Java cheat sheetJava cheat sheet
Java cheat sheet
Piyush Mittal
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
Sunil OS
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
Sunil OS
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
Sunil OS
 
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Kuntal Bhowmick
 
Java arrays
Java arraysJava arrays
Java arrays
Kuppusamy P
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
Raghuveer Guthikonda
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
PL/SQL:les curseurs
PL/SQL:les curseursPL/SQL:les curseurs
PL/SQL:les curseurs
Abdelouahed Abdou
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...
Pallavi Seth
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
Hemant Chetwani
 
Collection v3
Collection v3Collection v3
Collection v3
Sunil OS
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
Sunil OS
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
Sunil OS
 
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Kuntal Bhowmick
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
What is Constructors and Destructors in C++ (Explained with Example along wi...
What is Constructors and Destructors in  C++ (Explained with Example along wi...What is Constructors and Destructors in  C++ (Explained with Example along wi...
What is Constructors and Destructors in C++ (Explained with Example along wi...
Pallavi Seth
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
Hemant Chetwani
 

Viewers also liked (16)

Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat Sheet
GlowTouch
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
sudipv
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
Sireesh K
 
Css cheat-sheet-v3
Css cheat-sheet-v3Css cheat-sheet-v3
Css cheat-sheet-v3
Mariaa Maria
 
C# interview
C# interviewC# interview
C# interview
Thomson Reuters
 
C# Basics Quick Reference Sheet
C# Basics Quick Reference SheetC# Basics Quick Reference Sheet
C# Basics Quick Reference Sheet
FrescatiStory
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
sawarkar17
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
Haris Bin Zahid
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
Oum Saokosal
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objects
rahulsahay19
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
starlit electronics
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
Tuan Ngo
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
OUM SAOKOSAL
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat Sheet
GlowTouch
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
sudipv
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
Sireesh K
 
Css cheat-sheet-v3
Css cheat-sheet-v3Css cheat-sheet-v3
Css cheat-sheet-v3
Mariaa Maria
 
C# Basics Quick Reference Sheet
C# Basics Quick Reference SheetC# Basics Quick Reference Sheet
C# Basics Quick Reference Sheet
FrescatiStory
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
sawarkar17
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
Haris Bin Zahid
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
Oum Saokosal
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objects
rahulsahay19
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
Tuan Ngo
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
OUM SAOKOSAL
 
Ad

Similar to C# for C++ Programmers (20)

Get the Gist: .NET
Get the Gist: .NETGet the Gist: .NET
Get the Gist: .NET
russellgmorley
 
Introduction of OOPs and C++. Object oriented programming
Introduction of OOPs and C++. Object oriented programmingIntroduction of OOPs and C++. Object oriented programming
Introduction of OOPs and C++. Object oriented programming
Jatin541436
 
C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
Janani Anbarasan
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
report
reportreport
report
Quickoffice Test
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
ssuserb4d806
 
drupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptxdrupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptx
rukuntravel
 
Critical software developement
Critical software developementCritical software developement
Critical software developement
nedseb
 
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Patricia Aas
 
Effective refactoring
Effective refactoringEffective refactoring
Effective refactoring
Arnon Axelrod
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
 
C basics
C basicsC basics
C basics
Daniela Da Cruz
 
Cloud native development without the toil
Cloud native development without the toilCloud native development without the toil
Cloud native development without the toil
Ambassador Labs
 
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
Daniel Bryant
 
300 101 Dumps - Implementing Cisco IP Routing
300 101 Dumps - Implementing Cisco IP Routing300 101 Dumps - Implementing Cisco IP Routing
300 101 Dumps - Implementing Cisco IP Routing
Sara Rock
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
Cyber Security Alliance
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
DEF CON 27 - workshop - RICHARD GOLD - mind the gap
DEF CON 27 - workshop - RICHARD GOLD - mind the gapDEF CON 27 - workshop - RICHARD GOLD - mind the gap
DEF CON 27 - workshop - RICHARD GOLD - mind the gap
Felipe Prado
 
Whose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsWhose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problems
Sage Computing Services
 
Introduction of OOPs and C++. Object oriented programming
Introduction of OOPs and C++. Object oriented programmingIntroduction of OOPs and C++. Object oriented programming
Introduction of OOPs and C++. Object oriented programming
Jatin541436
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
ssuserb4d806
 
drupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptxdrupal ci cd concept cornel univercity.pptx
drupal ci cd concept cornel univercity.pptx
rukuntravel
 
Critical software developement
Critical software developementCritical software developement
Critical software developement
nedseb
 
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Undefined Behavior and Compiler Optimizations (NDC Oslo 2018)
Patricia Aas
 
Effective refactoring
Effective refactoringEffective refactoring
Effective refactoring
Arnon Axelrod
 
Cloud native development without the toil
Cloud native development without the toilCloud native development without the toil
Cloud native development without the toil
Ambassador Labs
 
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
GOTOpia 2/2021 "Cloud Native Development Without the Toil: An Overview of Pra...
Daniel Bryant
 
300 101 Dumps - Implementing Cisco IP Routing
300 101 Dumps - Implementing Cisco IP Routing300 101 Dumps - Implementing Cisco IP Routing
300 101 Dumps - Implementing Cisco IP Routing
Sara Rock
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
Cyber Security Alliance
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
DEF CON 27 - workshop - RICHARD GOLD - mind the gap
DEF CON 27 - workshop - RICHARD GOLD - mind the gapDEF CON 27 - workshop - RICHARD GOLD - mind the gap
DEF CON 27 - workshop - RICHARD GOLD - mind the gap
Felipe Prado
 
Whose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsWhose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problems
Sage Computing Services
 
Ad

Recently uploaded (20)

🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Foundation Models for Time Series : A Survey
Foundation Models for Time Series : A SurveyFoundation Models for Time Series : A Survey
Foundation Models for Time Series : A Survey
jayanthkalyanam1
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Foundation Models for Time Series : A Survey
Foundation Models for Time Series : A SurveyFoundation Models for Time Series : A Survey
Foundation Models for Time Series : A Survey
jayanthkalyanam1
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 

C# for C++ Programmers

  • 1. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 1 C# for C++ Programmers
  • 2. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 2 How C# Looks
  • 3. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 3 using genericCar; namespace Toyota; { public class Camry : Car { private static Camry camry; private Brake brake; public void main() { camry = new Camry(); camry.getBrake().ToString(); } public Camry() { this.brake = new Brake(); } public override Brake getBrake() { return this.brake; } } } C# Console Application Project
  • 4. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 4 using System.IO; namespace Toyota { public class Brake { string brakeName; public Brake() { this.brakeName = “Brake 1”; } public override string ToString() { System.Console.Out.Writeln(“I’m ” + this.brakeName); } } } Namespace GenericCar Class Car Public MustOverride Sub getBrake() End Class C# Class Library Project Vb.net Class Library Project
  • 5. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 5 Differences between C# and C++
  • 6. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 6 Pointers • Can be used in C# , but only in code blocks, methods, or classes marked with the unsafe keyword. • Primarily used for accessing Win32 functions that use pointers. class MyClass { unsafe int *pX; unsafe int MethodThatUsesPointers() { //can use pointers } int Method() { unsafe { //can use pointers } } }
  • 7. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 7 References, Classes, and Structs • References – are used in C#, which are effectively opaque pointers that don’t allow the aspects of pointer functionality that can cause bugs. • Classes and structs – are different in C#: – structs are value types, stored on the stack, and cannot inherit, – classes always reference types stored on the managed heap and are always derivatives of System.Object.
  • 8. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 8 Accessing native code • C# code can only access native code through PInvoke. class PInvoke { [DllImport("user32.dll")] public static extern int MessageBoxA( int h, string m, string c, int type); public static int Main() { return MessageBoxA(0, "Hello World!", "My Message Box", 0); } }
  • 9. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 9 Destruction • Destruction – Same syntax as for C++, but don’t need to declare it as virtual and shouldn’t add an access modifier. – C# cannot guarantee when a destructor will be called – called by the garbage collector. – Can force cleanup: System.GC.Collect(); – For deterministic destruction, classes should implement IDisposable.Dispose() – C# supports special syntax that mimics C++ classes that are instantiated on the stack where the destructor is called when it goes out of scope: using (MyClassThatHasDestructor mc = new MyClassThatHasDestructor) { //code that uses mc } // mc.Dispose() implicitly called when leaving block.
  • 10. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 10 Miscellaneous • Binary PE format – C# compiler will only generate managed assemblies – no native code. • Operator Overloading – C# can overload operators, but not as many. Not commonly used. • Preprocessor – C# has preprocessor directives, similar to C++ but far fewer. No separate preprocessor – compiler does preprocessing. – C# doesn’t need #include – no need to declare compiler symbols used in code but not yet defined.
  • 11. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 11 Miscellaneous • C# doesn’t require a semicolon after a class • C# doesn’t support class objects on the stack. • const only at compile time, readonly set once at runtime in constructor. • C# has no function pointers – delegates instead.
  • 12. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 12 C# New Features
  • 13. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 13 Delegates delegate void AnOperation(int x); class AClass { void AMethod(int i) { System.Console.WriteLine(“Number is ” + i.ToString()); } static int Main(string[] args) { AClass aClass = new AClass(); AnOperation anOperation = new AnOperation(AClass.AMethod); anOperation(4); } } stdio console output: Number is 4 – When delegate returns a void, is a ‘multicast’ delegate and can represent more than one method. += and -= can be used to add and remove a method from a multicast delegate.
  • 14. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 14 Events • An event source EventSourceClass declares an event with this special syntax: public delegate void EventClass(obj Sender, EventArgs e); public event EventClass SourceEvent; • Client event handlers must look like this: void MyEventCallback(object sender, EventArgs e) { //handle event } • Client event handlers are added to an event source like this: EventSourceClass.SourceEvent += MyEventCallback; • An event source then invokes the event like this: SourceEvent(this, new EventArgs());
  • 15. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 15 Attributes and Properties • Attributes – meta info that can be accessed at runtime [WebMethod] public ShippingPreference[] GetShippingPreferences(ShoppingCart shoppingCart, CustomerInformation customerInformation) { } • Properties class ContainsProperty { private int age; public int Age { get { return age;} set { age = value;} } }
  • 16. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 16 Exceptions • Exceptions in C# support a finally block: try { //normal execution path } catch (Exception ex) { //execution jumps to here if Exception or derivative //is thrown in try block. } finally { //ALWAYS executes, either after try or catch clause executes. }
  • 17. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 17 Miscellaneous • Interfaces • Threading lock() statement (shortcut for System.Threading.Monitor) • Boxing – Value types are primitives. – Value types can be treated as objects – Even literal types can be treated as objects. string age = 42.ToString(); int i = 20; object o = i;
  • 18. C++ features unsupported in C# © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 18 • No templates – generics instead (C++/CLI has both) • No multiple inheritance for base classes.
  • 19. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 19 Configuration
  • 20. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 20 XML File Based • .NET assemblies use XML-based configuration files named ExecutableName.exe.config • Registry is not commonly used for .NET applications.
  • 21. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 21 File Format • ExecutableName.exe.config looks like: <configuration> <system.runtime.remoting> <application> <channels> <channel ref="tcp" port="9091" /> </channels> </application> </system.runtime.remoting> <appSettings> <!-- SERVICE --> <!-- false will cause service to run as console application, true requires installing and running as a Windows service --> <add key = "Service.isService" value = "false" /> <add key = "Service.eventsourcestring" value = "CCLI Service" /> <add key = "Service.servicename" value = "CCLI Service" /> <add key = "ServiceAssemblyName" value = "Framework" /> <add key = "ServiceClassNameConsole" value = "StarPraise.Core.ConsoleBootstrapper" /> <add key = "ServiceClassNameService" value = "StarPraise.Core.ComponentController" /> <add key = "Service.strStarting" value = "Service starting..." /> <add key = "Service.strStopping" value = "Service Stopping..." /> <!-- Configuration to use DefaultLogger - writing straight to file. Only for testing - NOT FOR PRODUCTION USE. --> <add key = "Logger.loggerAssembly" value = "Framework" /> <add key = "Logger.loggerclassname" value = "StarPraise.Core.DefaultLogger" /> … </configuration>
  • 22. Accessing Configuration Values © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 22 static protected Logger getInstance() { if (Logger.loggerInstance == null) { try { ObjectHandle obj = Activator.CreateInstance( System.Configuration.ConfigurationManager.AppSettings[Logger.loggerAssembly], System.Configuration.ConfigurationManager.AppSettings[Logger.loggerclassname]); Logger.loggerInstance = (Logger) obj.Unwrap(); Logger.loggerInstance.Start(); } catch (Exception ex) { throw new RuntimeException(ex.ToString(), new ComponentIdentity("Logger"), "getInstance"); } }
  • 23. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 23 Application Types
  • 24. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 24 Types There are five primary application (‘executable’) projects in Visual Studio: • Console Applications • Services • Forms Applications • Web Applications • Web Services
  • 25. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 25 Form Applications • VS.NET creates Main and adds to the form application project. • Windows Message Pump is encapsulated entirely within classes contained in System.Windows. • System.Windows.Forms.Form is type automatically created by VS.NET for forms application projects.
  • 26. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 26 Forms Applications using System; using System.Collections.Generic; using System.Windows.Forms; namespace CompassPoint.ECommerce.OrderProcessingServ ices { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefa ult(false); Application.Run(new OrderProcessingWebServiceTest()); } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CompassPoint.ECommerce.OrderProcessingServices { public partial class OrderProcessingWebServiceTest : Form { public OrderProcessingWebServiceTest() { InitializeComponent(); } } }
  • 27. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 27 Web Applications • They are hosted in IIS. • A variety of compile options from compile when accessed to pre-compile including partial compile in the creamy middle! • When webpage.aspx is accessed, – IIS delegates to the ASP.NET runtime which • creates a runtime object model for the page, • Reads the page • Returns all markup to IIS to return to browser except • Embedded runat=server marked code in the page which it runs in the runtime object model environment and returns the resulting markup.
  • 28. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 28 Web Services • When a webservice.asmx is accessed, the same thing happens, but SOAP ‘method’ invocation requests are redirected to methods in the web service marked with a special attribute.
  • 29. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 29 Web Services [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class OrderProcessingService : System.Web.Services.WebService, IOrderManager { [WebMethod] public ShippingPreference[] GetShippingPreferences(ShoppingCart shoppingCart, CustomerInformation customerInformation) { ….
  • 30. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 30 Web Application and Service Configuration • As for applications, configuration is stored in an XML file. • XML file is of same format as for other types of applications. • For both, the file is named web.config.
  • 31. © 2007 Compass Point, Inc. 9434 SW 55th Avenue  Portland OR 97219  Phone: 503.329.1138  [email protected] www.compass-point.net 31 Discussion