SlideShare a Scribd company logo
1 of 31
© 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

More Related Content

What's hot

OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
Crear una dll en C++ y llamarla con la interfaz C#
Crear una dll en C++ y llamarla con la interfaz C#Crear una dll en C++ y llamarla con la interfaz C#
Crear una dll en C++ y llamarla con la interfaz C#Ángel Acaymo M. G.
 
Hot C++: Rvalue References And Move Semantics
Hot C++: Rvalue References And Move SemanticsHot C++: Rvalue References And Move Semantics
Hot C++: Rvalue References And Move SemanticsAndrey Upadyshev
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?NAVER D2
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Kamlesh Makvana
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySqlkamal kotecha
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismCHAITALIUKE1
 
Formation C# - Cours 1 - Introduction, premiers pas, concepts
Formation C# - Cours 1 - Introduction, premiers pas, conceptsFormation C# - Cours 1 - Introduction, premiers pas, concepts
Formation C# - Cours 1 - Introduction, premiers pas, conceptskemenaran
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List KataOlve Maudal
 

What's hot (20)

OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
Crear una dll en C++ y llamarla con la interfaz C#
Crear una dll en C++ y llamarla con la interfaz C#Crear una dll en C++ y llamarla con la interfaz C#
Crear una dll en C++ y llamarla con la interfaz C#
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Hot C++: Rvalue References And Move Semantics
Hot C++: Rvalue References And Move SemanticsHot C++: Rvalue References And Move Semantics
Hot C++: Rvalue References And Move Semantics
 
C#ppt
C#pptC#ppt
C#ppt
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
C# in depth
C# in depthC# in depth
C# in depth
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
C++ oop
C++ oopC++ oop
C++ oop
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphism
 
Formation C# - Cours 1 - Introduction, premiers pas, concepts
Formation C# - Cours 1 - Introduction, premiers pas, conceptsFormation C# - Cours 1 - Introduction, premiers pas, concepts
Formation C# - Cours 1 - Introduction, premiers pas, concepts
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List Kata
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 

Viewers also liked

C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat SheetGlowTouch
 
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-v3Mariaa Maria
 
C# Basics Quick Reference Sheet
C# Basics Quick Reference SheetC# Basics Quick Reference Sheet
C# Basics Quick Reference SheetFrescatiStory
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in javasawarkar17
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and InterfaceHaris Bin Zahid
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objectsrahulsahay19
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro 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 ClassOUM SAOKOSAL
 

Viewers also liked (16)

Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat Sheet
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
Css cheat-sheet-v3
Css cheat-sheet-v3Css cheat-sheet-v3
Css cheat-sheet-v3
 
C# interview
C# interviewC# interview
C# interview
 
C# Basics Quick Reference Sheet
C# Basics Quick Reference SheetC# Basics Quick Reference Sheet
C# Basics Quick Reference Sheet
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objects
 
C++ classes
C++ classesC++ classes
C++ classes
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
 

Similar to C# for C++ Programmers: Key Differences and New Features

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 MelayiMuhammed Thanveer M
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptxssuserb4d806
 
Critical software developement
Critical software developementCritical software developement
Critical software developementnedseb
 
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 refactoringArnon Axelrod
 
Cloud native development without the toil
Cloud native development without the toilCloud native development without the toil
Cloud native development without the toilAmbassador 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 RoutingSara 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
 
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 gapFelipe 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 problemsSage Computing Services
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaPantheon
 
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...Daniel Bryant
 

Similar to C# for C++ Programmers: Key Differences and New Features (20)

Get the Gist: .NET
Get the Gist: .NETGet the Gist: .NET
Get the Gist: .NET
 
C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
 
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
 
report
reportreport
report
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
Critical software developement
Critical software developementCritical software developement
Critical software developement
 
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)
 
Effective refactoring
Effective refactoringEffective refactoring
Effective refactoring
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
C basics
C basicsC basics
C basics
 
Cloud native development without the toil
Cloud native development without the toilCloud native development without the toil
Cloud native development without the toil
 
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...
 
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
 
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...
 
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
 
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
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
JAX London 2021: Jumpstart Your Cloud Native Development: An Overview of Prac...
 
C++
C++C++
C++
 

Recently uploaded

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

Recently uploaded (20)

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

C# for C++ Programmers: Key Differences and New Features

  • 1. © 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
  • 2. © 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
  • 3. © 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
  • 4. © 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
  • 5. © 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++
  • 6. © 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 } } }
  • 7. © 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.
  • 8. © 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); } }
  • 9. © 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.
  • 10. © 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.
  • 11. © 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.
  • 12. © 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
  • 13. © 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.
  • 14. © 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());
  • 15. © 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;} } }
  • 16. © 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. }
  • 17. © 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;
  • 18. 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.
  • 19. © 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
  • 20. © 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.
  • 21. © 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>
  • 22. 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"); } }
  • 23. © 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
  • 24. © 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
  • 25. © 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.
  • 26. © 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(); } } }
  • 27. © 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.
  • 28. © 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.
  • 29. © 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) { ….
  • 30. © 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.
  • 31. © 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