SlideShare a Scribd company logo
C++ 프로그래머를 위한 C#
㈜넥슨
신규개발3본부 개발1실 GTR팀 성능연구유닛
김재석
NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#
책임연구원
2010/2011, 마비노기2
2006/2009, 마비노기 영웅전
테크니컬 디렉터
2004/2005, 마비노기
2003/2004, 프로젝트 T2
2001/2003, Oz World
[ɡ̊ɪm̚ ʨæːsɤk̚]
/ɡim ɟɛːzʌɡ/
Agenda
Visual Studio .NET Rainer
.NET Framework 1.0 C# 1.0
Visual Studio .NET 2003 Everett
.NET Framework 1.1, C# 1.2
Visual Studio 2005 Whidbey
.NET Framework 2.0, C# 2,0
.NET Framework 3.0 WinFX
Visual Studio 2008 Orcas
.NET Framework 3.5, C# 3.0
Visual Studio 2010 Dev10
.NET Framework 4.0, C# 4.0
Reactive Extensions for .NET Framework 3.5 SP1
Visual Studio .NET Rainer
.NET Framework 1.0 / C# 1.0
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
C# 1.0 – Managed Code
Common Type System
Classes
Structures
Enumerations
Interfaces
Delegates
Attributes
Directives
Visual Studio® .NET
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Common Type System
Primitive Types
Field
Method
Property
Event
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Primitive Types
Byte
Int16
Int32
Int64
Single
Double
Boolean
Char
Decimal
IntPtr
String
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Field
// C#
const int constant = 0;
readonly int readOnlyField;
// C++
static const int constant = 0;
const int readOnlyField;
mutable int mutableField;
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Field (cont.)
Field ≠ variable
default(T) if not initialized
• null if reference type
• 0 if value type
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Method
Member function with CV-qualifier
class Object
{
public:
String ToString() const
{
return const_cast<Object*>(this)
->ToString();
}
virtual String ToString();
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Method (cont.)
// C#
void CallByRef(ref int value);
bool TryGetValue(out int value);
// C++
void CallByRef(int& value);
bool TryGetValue(/*out*/int& value);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Property
Get Method/Set Method ≠ reference to type
// C#
variable = obj.PropertyName;
obj.PropertyName = value
// C++
variable = obj->get_PropertyName();
obj->setPropertyName(value);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Property (cont.)
Indexed property ≠ index operator []
int this[int index]
{
get { return array[index]; }
set { array[index] = value; }
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Property (cont.)
Implementation: lazy evaluation class
class Property<typename T>
{
operator T() const;
Property& operator=(const T&
value);
Property& operator=(const
Property& value);
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Property (cont.)
VC 7.1 or higher: property extended storage-
class modifier
virtual TypeName get_PropertyName();
virtual void set_PropertyName(const
TypeName& value);
__declspec(property(get=get_Property
Name, put=set_PropertyName))
TypeName PropertyName;
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Event
Multicast delegate
// C#
obj.EventName += someDelegate;
obj.EventName -= someDelegate;
if (obj.EventName != null) obj.EventName();
// C++
obj->add_EventName(someDelegate);
obj->remove_EventName(someDelegate);
obj->raise_EventName();
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Classes
Finalizer ≠ destructor
GC.ReRegisterForFinalize(this);
GC.SuppressFinalize(this);
// C#
GC.KeepAlive(value);
// C++
Pointer<Object> keepAlive(value);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Classes (cont.)
Prevent R6025 – Pure virtual function call
__forceinline void Release()
{
if (--referenceCounter == 0)
{
Finalize();
delete this;
}
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Classes (cont.)
Type initializer a.k.a. static constructor
namespace
{
class Static : … ;
Pointer<Static> _static;
}
…
if (_static == NULL)
{
_static.CompareExchange(Pointer<Static>(
new Static), Pointer<Static>(NULL));
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Classes (cont.)
Sealed class
template <typename T>
class Sealed
{
private:
friend typename T;
Sealed() { }
~Sealed() { }
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Structures
Lightweight – Value types
Default constructor / finalizer
• NEVER let contain unmanaged resources
Expert only
• Box/Unbox cost
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Enumerations
Value types
string[] Enum.GetNames()
TEnum[] Enum.GetValues()
TEnum Enum.Parse(string s)
bool Enum.TryParse(
string s, out TEnum @enum)
TEnum TEnum.MaxValue { get; }
TEnum TEnum.MinValue { get; }
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Interfaces
Virtual inheritance
template <>
class Task<void> : public Object,
public virtual IAsyncResult,
public virtual IDisposable
{
…
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Delegates
Closures or managed functors
Calling conventions:
• cdecl
• stdcall
• fastcall
• thiscall
• function object
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Delegates (cont.)
#define DEFINE_DELEGATE(TPARAMS, PARAMS,
ARGS)
template <typename TResult TPARAMS>
class delegate<TResult(PARAMS)> …
#define DELEGATE_TPARAMS , typename T1
#define DELEGATE_PARAMS T1 arg1
#define DELEGATE_ARGS arg1
DEFINE_DELEGATE(DELEGATE_TPARAMS,
DELEGATE_PARAMS, DELEGATE_ARGS);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Attributes
template <typename T>
class CustomAttribute
{
public:
static const int get_Value() { return
value; }
private:
static int value;
};
#define CUSTOM_ATTRIBUTE(Type, _v) 
int CustomAttribute<Type>::value = _v
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Directives
using directive (C#) ≈ using directive (C++)
Assemblies are referenced.
#include directive (C++)
package / import declarations (Java)
#define directive
defines a symbol
assigns a value to a symbol
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio .NET 2003 Everett
.NET Framework 1.1 / C# 1.2
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
C# 1.2 – Bug Fix
IDisposable interface
• IEnumerator interface
foreach (object obj in collection)
// TEnumerator enumerator =
// collection.GetEnumerator();
{
}
// if (enumerator is IDisposable)
// enumerator.Dispose();
Visual Studio® .NET 2003
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio 2005 Whidbey
.NET Framework 2.0 / C# 2.0
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
C# 2.0 – Generic
Generics
Iterators
Partial Classes
Nullable Types
Anonymous Methods
Static Classes
Property Accessor Accessibilities
Delegates
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio® 2005
Generics
System.Collections.Generic
• List<T> std::vector<T>
• Queue<T> std::queue<T>
• Stack<T> std::stack<T>
• LinkedList<T> std::list<T>
• Dictionary<TKey, TValue>
std::map<Key, T>
• HashSet<T> std::set<T>
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Iterators
IEnumerable<T> Where<T>(
IEnumerable<T> source,
Func<T, bool> predicate)
{
if (source == null) yield break;
foreach (T value in source)
{
if (!predicate(value)) continue;
yield return value;
}
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Partial Classes
// Generated.Designer.cs
[CLSCompliant]
partial class Generated : ICloneable
{ … }
// Generated.cs
[Serializable]
partial class Generated : IDisposable
{ … }
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Nullable Types
Nullable<T> where T : struct
Coalescing operator ??
int? nullable = null;
int value = nullable ??
default(int);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Anonymous Methods
// C# 2.0
Func<Type, bool> predicate =
// nested type in C# 1.2
delegate(Type value)
{
return value == default(Type);
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Static Classes
Classes which are both abstract and sealed.
public static class Helper
{
public static int GetHash(object obj)
{
return obj.GetHashCode();
}
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Property Accessor
Accessibilities
// C# 1.2
public Type PropertyName
{ get { return field; } }
internal void SetPropertyName(Type value)
{ fieldName = value; }
// C# 2.0
public Type PropertyName
{
get { return fieldName; }
internal set { fieldName = value; }
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Delegates
string Covariance() …
Func<object> function =
new Func<object>(Covariance);
void Contravariance(object arg);
Action<string> action =
new Action<string>(
Contravariance);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Delegates (cont.)
// C# 1.2
Action action =
new Action(obj.MethodName);
// C# 2.0
Action action = obj.MethodName;
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio 2008 Orcas
.NET Framework 3.5 / C# 3.0
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
C# 3.0 – LINQ
Implicitly Type Local Variables and Arrays
Object Initializers
Collection Initializers
Extension Methods
Anonymous Types
Lambda Expressions
Query Keywords
Auto-Implemented Properties
Partial Method Definitions
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio® 2008
Implicitly Type Local
Variables and Arrays
// C# 2.0
Dictionary<string, object> dict =
new Dictionary<string, object>();
Type[] types = new Type[]
{ typeof(int) };
// C# 3.0
var dict =
new Dictionary<string, object>();
var types = new[] { typeof(int) };
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Object Initializers
// C# 2.0
SomeKeyValue pair = new SomeKeyValue();
value.Name = “anonymous”;
value.Value = null;
// C# 3.0
var value = new SomeKeyValue()
{
Name = “anonymous”,
Value = null,
};
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Collection Initializers
// C# 2.0
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
// C# 3.0
var list = new List<int> { 1, 2 };
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Extension Methods
static class ComponentExtensions
{
static void DoSomething(
this IComponent component,
T arg) { … }
}
ComponentExtensions.Do(component, arg);
component.DoSomething(arg);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Anonymous Types
foreach (var value in from row in table
select new
{
Type = row.GetType(),
Hash = row.GetHashCode(),
})
{
Console.WriteLine(“{{ Type = {0}, Hash = {1} }}”,
value.Type, value.Hash);
Console.WriteLine(value);
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Lambda Expressions
// C# 2.0
Func<Type, bool> predicate =
delegate(Type value)
{
return value == default(Type);
};
// C# 3.0
Func<Type, bool> predicate =
value => value == default(Type);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Query Keywords
var q = from c in categories
join p in products
on c.ID equals p.CID
orderby c.ID,
p.Price descending
group p.Price by c.ID into g
let cid = g.Key
where Predicate(cid)
select g.Average();
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Query Keywords (cont.)
var q = categories
.Join(products,
c => c.ID, p => p.CID,
(c, p) =>
new { c = c, p = p })
.OrderBy(_ => _.c.ID)
.ThenByDescending(_ => _.p.Price)
.GroupBy(_ => _.c.ID, _.p.Price)
.Select(g =>
new { g = g, cid = g.Key })
.Where(_ => Predicate(_.cid))
.Select(_ => _.g.Average());
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Auto-Implemented
Properties
// C# 2.0
public Type PropertyName
{
get { return fieldName; }
internal set { fieldName = value; }
}
// C# 3.0
public Type PropertyName
{ get; internal set; }
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Partial Method
Definitions
// Generated.Designer.cs
partial class Generated
{
Generated() { OnInitialized(); }
partial void OnInitialized();
}
// Generated.cs
partial class Generated
{
partial void OnInitialized() { … }
}
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Reactive Extensions for .NET Framework 3.5 SP1
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
More LINQ with System.Interactive – Getting Started by Bart De Smet
Reactive Extensions
Task Parallel Library ∈ .NET Framework 4.0
Observer Design Pattern
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Task Parallel Library
System.Collections.Concurrent
• ConcurrentBag<T>
tbb::concurrent_vector<T>
• ConcurrentQueue<T>
tbb::concurrent_queue<T>
• ConcurrentStack<T>
tbb::concurrent_stack<T>
• ConcurrentDictionary<TKey, TValue>
tbb::concurrent_hash_map<Key, T>
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Task Parallel Library
(cont.)
System.Threading.Tasks
// C# 3.0
ThreadPool.QueueUserWorkItem(
callback, state);
// C# 4.0 or Rx
Task.Factory.StartNew(
action, state);
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Observer Design Pattern
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
More LINQ with System.Interactive – Getting Started by Bart De Smet
Observer Design Pattern
(Further reading)
Duality of IEnumerable<T> / IObservable<T>
Reactive Framework Finally Explained
More LINQ with System.Interactive series
VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Q&A

More Related Content

PDF
김재석, C++ 프로그래머를 위한 C#, NDC2011
PPT
Constructor and destructor in C++
PPT
Bca 2nd sem u-2 classes & objects
PPTX
Oop objects_classes
PPTX
Dependency Breaking Techniques
PPT
Refactoring - improving the smell of your code
PPT
SystemVerilog OOP Ovm Features Summary
PPT
TechTalk - Dotnet
김재석, C++ 프로그래머를 위한 C#, NDC2011
Constructor and destructor in C++
Bca 2nd sem u-2 classes & objects
Oop objects_classes
Dependency Breaking Techniques
Refactoring - improving the smell of your code
SystemVerilog OOP Ovm Features Summary
TechTalk - Dotnet

What's hot (20)

PDF
Better Code: Concurrency
PDF
Introduction to web programming for java and c# programmers by @drpicox
PDF
C++ aptitude
PDF
C# for-java-developers
PDF
One Year of Clean Architecture - The Good, The Bad and The Bob
PDF
Enter the gradle
DOCX
Java PRACTICAL file
PPTX
SoCal Code Camp 2015: An introduction to Java 8
PPTX
Navigating the xDD Alphabet Soup
PDF
C++ Interface Versioning
PPTX
How Data Flow analysis works in a static code analyzer
PDF
Object Oriented Programming using C++ - Part 5
PDF
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
PDF
Object Oriented Programming using C++ - Part 1
PPT
Java basic understand OOP
PDF
C++aptitude questions and answers
PDF
Object Oriented Programming using C++ - Part 3
PPTX
Constructors and destructors
PDF
2006 Small Scheme
PDF
PVS-Studio in 2021 - Error Examples
Better Code: Concurrency
Introduction to web programming for java and c# programmers by @drpicox
C++ aptitude
C# for-java-developers
One Year of Clean Architecture - The Good, The Bad and The Bob
Enter the gradle
Java PRACTICAL file
SoCal Code Camp 2015: An introduction to Java 8
Navigating the xDD Alphabet Soup
C++ Interface Versioning
How Data Flow analysis works in a static code analyzer
Object Oriented Programming using C++ - Part 5
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Object Oriented Programming using C++ - Part 1
Java basic understand OOP
C++aptitude questions and answers
Object Oriented Programming using C++ - Part 3
Constructors and destructors
2006 Small Scheme
PVS-Studio in 2021 - Error Examples
Ad

Viewers also liked (20)

PDF
NDC 2014, 피할 수 없는 문자열의 세계
PDF
Preprocessor Programming
PDF
리소스 중심의 서든어택2 실시간 메모리 프로파일링 시스템 개발기
PDF
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
PDF
김재석, 패킷 지옥으로부터 탈출, NDC2010
PDF
월간 마이크로소프트웨어 창간 28주년 기념 C++ 개발자를 위한 게임 프로그래밍 실전 기법 세미나, C++ 게임 개발자를 위한 C# 활용기법
PDF
NDC 2012, Gamification 001: 실전 감량 사례로 알아보는 메카닉
PPTX
NDC 2011, 네트워크 비동기 통신, 합의점의 길목에서
PDF
NDC 2010, 패킷 지옥으로부터 탈출
PDF
C# Game Server
PDF
[Td 2015]너에게만 나는 반응해 반응형 응용프로그램(이규원)
PPTX
NDC 11 자이언트 서버의 비밀
PPT
[NDC] 인디 게임 개발사의 콘솔도전기
PDF
NDC 2010 이은석 - 마비노기 영웅전 포스트모템 1부
PDF
NDC 2013, 마비노기 영웅전 개발 테크니컬 포스트-모템
PDF
NDC12_Lockless게임서버설계와구현
PDF
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
PDF
NDC 2015 이광영 [야생의 땅: 듀랑고] 전투 시스템 개발 일지
PPTX
공성대전 C# 사용기
PDF
Iocp 기본 구조 이해
NDC 2014, 피할 수 없는 문자열의 세계
Preprocessor Programming
리소스 중심의 서든어택2 실시간 메모리 프로파일링 시스템 개발기
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
김재석, 패킷 지옥으로부터 탈출, NDC2010
월간 마이크로소프트웨어 창간 28주년 기념 C++ 개발자를 위한 게임 프로그래밍 실전 기법 세미나, C++ 게임 개발자를 위한 C# 활용기법
NDC 2012, Gamification 001: 실전 감량 사례로 알아보는 메카닉
NDC 2011, 네트워크 비동기 통신, 합의점의 길목에서
NDC 2010, 패킷 지옥으로부터 탈출
C# Game Server
[Td 2015]너에게만 나는 반응해 반응형 응용프로그램(이규원)
NDC 11 자이언트 서버의 비밀
[NDC] 인디 게임 개발사의 콘솔도전기
NDC 2010 이은석 - 마비노기 영웅전 포스트모템 1부
NDC 2013, 마비노기 영웅전 개발 테크니컬 포스트-모템
NDC12_Lockless게임서버설계와구현
NDC 2016, [슈판워] 맨땅에서 데이터 분석 시스템 만들어나가기
NDC 2015 이광영 [야생의 땅: 듀랑고] 전투 시스템 개발 일지
공성대전 C# 사용기
Iocp 기본 구조 이해
Ad

Similar to NDC 2011, C++ 프로그래머를 위한 C# (20)

DOCX
C# Unit 1 notes
PPTX
PPT
03 oo with-c-sharp
PDF
1204csharp
PPTX
PDC Video on C# 4.0 Futures
PPT
Object Oriented Programming In .Net
PPTX
Evolution of c# - by K.Jegan
PPT
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
PPT
Introduction-to-Csharp.ppt
PPT
Introduction-to-Csharp programacion orientada a objetos
PPT
Introduction-to-Csharp.ppt
PPT
Introduction to-csharp
PPT
Chapter 1 Presentation
PDF
Introduction to c#
PDF
Introduction To Csharp
PPT
C#
ODP
C# 3.0 Course
PDF
C# for Java Developers
PPTX
Whats New In C# 4 0 - NetPonto
C# Unit 1 notes
03 oo with-c-sharp
1204csharp
PDC Video on C# 4.0 Futures
Object Oriented Programming In .Net
Evolution of c# - by K.Jegan
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
Introduction-to-Csharp.ppt
Introduction-to-Csharp programacion orientada a objetos
Introduction-to-Csharp.ppt
Introduction to-csharp
Chapter 1 Presentation
Introduction to c#
Introduction To Csharp
C#
C# 3.0 Course
C# for Java Developers
Whats New In C# 4 0 - NetPonto

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Tartificialntelligence_presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
cloud_computing_Infrastucture_as_cloud_p
OMC Textile Division Presentation 2021.pptx
Machine learning based COVID-19 study performance prediction
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TLE Review Electricity (Electricity).pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Getting Started with Data Integration: FME Form 101
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A comparative study of natural language inference in Swahili using monolingua...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Tartificialntelligence_presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

NDC 2011, C++ 프로그래머를 위한 C#

  • 1. C++ 프로그래머를 위한 C# ㈜넥슨 신규개발3본부 개발1실 GTR팀 성능연구유닛 김재석
  • 4. 책임연구원 2010/2011, 마비노기2 2006/2009, 마비노기 영웅전 테크니컬 디렉터 2004/2005, 마비노기 2003/2004, 프로젝트 T2 2001/2003, Oz World [ɡ̊ɪm̚ ʨæːsɤk̚] /ɡim ɟɛːzʌɡ/
  • 5. Agenda Visual Studio .NET Rainer .NET Framework 1.0 C# 1.0 Visual Studio .NET 2003 Everett .NET Framework 1.1, C# 1.2 Visual Studio 2005 Whidbey .NET Framework 2.0, C# 2,0 .NET Framework 3.0 WinFX Visual Studio 2008 Orcas .NET Framework 3.5, C# 3.0 Visual Studio 2010 Dev10 .NET Framework 4.0, C# 4.0 Reactive Extensions for .NET Framework 3.5 SP1
  • 6. Visual Studio .NET Rainer .NET Framework 1.0 / C# 1.0 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 7. C# 1.0 – Managed Code Common Type System Classes Structures Enumerations Interfaces Delegates Attributes Directives Visual Studio® .NET VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 8. Common Type System Primitive Types Field Method Property Event VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 10. Field // C# const int constant = 0; readonly int readOnlyField; // C++ static const int constant = 0; const int readOnlyField; mutable int mutableField; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 11. Field (cont.) Field ≠ variable default(T) if not initialized • null if reference type • 0 if value type VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 12. Method Member function with CV-qualifier class Object { public: String ToString() const { return const_cast<Object*>(this) ->ToString(); } virtual String ToString(); }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 13. Method (cont.) // C# void CallByRef(ref int value); bool TryGetValue(out int value); // C++ void CallByRef(int& value); bool TryGetValue(/*out*/int& value); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 14. Property Get Method/Set Method ≠ reference to type // C# variable = obj.PropertyName; obj.PropertyName = value // C++ variable = obj->get_PropertyName(); obj->setPropertyName(value); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 15. Property (cont.) Indexed property ≠ index operator [] int this[int index] { get { return array[index]; } set { array[index] = value; } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 16. Property (cont.) Implementation: lazy evaluation class class Property<typename T> { operator T() const; Property& operator=(const T& value); Property& operator=(const Property& value); }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 17. Property (cont.) VC 7.1 or higher: property extended storage- class modifier virtual TypeName get_PropertyName(); virtual void set_PropertyName(const TypeName& value); __declspec(property(get=get_Property Name, put=set_PropertyName)) TypeName PropertyName; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 18. Event Multicast delegate // C# obj.EventName += someDelegate; obj.EventName -= someDelegate; if (obj.EventName != null) obj.EventName(); // C++ obj->add_EventName(someDelegate); obj->remove_EventName(someDelegate); obj->raise_EventName(); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 19. Classes Finalizer ≠ destructor GC.ReRegisterForFinalize(this); GC.SuppressFinalize(this); // C# GC.KeepAlive(value); // C++ Pointer<Object> keepAlive(value); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 20. Classes (cont.) Prevent R6025 – Pure virtual function call __forceinline void Release() { if (--referenceCounter == 0) { Finalize(); delete this; } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 21. Classes (cont.) Type initializer a.k.a. static constructor namespace { class Static : … ; Pointer<Static> _static; } … if (_static == NULL) { _static.CompareExchange(Pointer<Static>( new Static), Pointer<Static>(NULL)); } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 22. Classes (cont.) Sealed class template <typename T> class Sealed { private: friend typename T; Sealed() { } ~Sealed() { } }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 23. Structures Lightweight – Value types Default constructor / finalizer • NEVER let contain unmanaged resources Expert only • Box/Unbox cost VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 24. Enumerations Value types string[] Enum.GetNames() TEnum[] Enum.GetValues() TEnum Enum.Parse(string s) bool Enum.TryParse( string s, out TEnum @enum) TEnum TEnum.MaxValue { get; } TEnum TEnum.MinValue { get; } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 25. Interfaces Virtual inheritance template <> class Task<void> : public Object, public virtual IAsyncResult, public virtual IDisposable { … }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 26. Delegates Closures or managed functors Calling conventions: • cdecl • stdcall • fastcall • thiscall • function object VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 27. Delegates (cont.) #define DEFINE_DELEGATE(TPARAMS, PARAMS, ARGS) template <typename TResult TPARAMS> class delegate<TResult(PARAMS)> … #define DELEGATE_TPARAMS , typename T1 #define DELEGATE_PARAMS T1 arg1 #define DELEGATE_ARGS arg1 DEFINE_DELEGATE(DELEGATE_TPARAMS, DELEGATE_PARAMS, DELEGATE_ARGS); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 28. Attributes template <typename T> class CustomAttribute { public: static const int get_Value() { return value; } private: static int value; }; #define CUSTOM_ATTRIBUTE(Type, _v) int CustomAttribute<Type>::value = _v VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 29. Directives using directive (C#) ≈ using directive (C++) Assemblies are referenced. #include directive (C++) package / import declarations (Java) #define directive defines a symbol assigns a value to a symbol VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 30. Visual Studio .NET 2003 Everett .NET Framework 1.1 / C# 1.2 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 31. C# 1.2 – Bug Fix IDisposable interface • IEnumerator interface foreach (object obj in collection) // TEnumerator enumerator = // collection.GetEnumerator(); { } // if (enumerator is IDisposable) // enumerator.Dispose(); Visual Studio® .NET 2003 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 32. Visual Studio 2005 Whidbey .NET Framework 2.0 / C# 2.0 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 33. C# 2.0 – Generic Generics Iterators Partial Classes Nullable Types Anonymous Methods Static Classes Property Accessor Accessibilities Delegates VS .NET VS .NET 2003 VS 2005 VS 2008 Rx Visual Studio® 2005
  • 34. Generics System.Collections.Generic • List<T> std::vector<T> • Queue<T> std::queue<T> • Stack<T> std::stack<T> • LinkedList<T> std::list<T> • Dictionary<TKey, TValue> std::map<Key, T> • HashSet<T> std::set<T> VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 35. Iterators IEnumerable<T> Where<T>( IEnumerable<T> source, Func<T, bool> predicate) { if (source == null) yield break; foreach (T value in source) { if (!predicate(value)) continue; yield return value; } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 36. Partial Classes // Generated.Designer.cs [CLSCompliant] partial class Generated : ICloneable { … } // Generated.cs [Serializable] partial class Generated : IDisposable { … } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 37. Nullable Types Nullable<T> where T : struct Coalescing operator ?? int? nullable = null; int value = nullable ?? default(int); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 38. Anonymous Methods // C# 2.0 Func<Type, bool> predicate = // nested type in C# 1.2 delegate(Type value) { return value == default(Type); }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 39. Static Classes Classes which are both abstract and sealed. public static class Helper { public static int GetHash(object obj) { return obj.GetHashCode(); } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 40. Property Accessor Accessibilities // C# 1.2 public Type PropertyName { get { return field; } } internal void SetPropertyName(Type value) { fieldName = value; } // C# 2.0 public Type PropertyName { get { return fieldName; } internal set { fieldName = value; } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 41. Delegates string Covariance() … Func<object> function = new Func<object>(Covariance); void Contravariance(object arg); Action<string> action = new Action<string>( Contravariance); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 42. Delegates (cont.) // C# 1.2 Action action = new Action(obj.MethodName); // C# 2.0 Action action = obj.MethodName; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 43. Visual Studio 2008 Orcas .NET Framework 3.5 / C# 3.0 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 44. C# 3.0 – LINQ Implicitly Type Local Variables and Arrays Object Initializers Collection Initializers Extension Methods Anonymous Types Lambda Expressions Query Keywords Auto-Implemented Properties Partial Method Definitions VS .NET VS .NET 2003 VS 2005 VS 2008 Rx Visual Studio® 2008
  • 45. Implicitly Type Local Variables and Arrays // C# 2.0 Dictionary<string, object> dict = new Dictionary<string, object>(); Type[] types = new Type[] { typeof(int) }; // C# 3.0 var dict = new Dictionary<string, object>(); var types = new[] { typeof(int) }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 46. Object Initializers // C# 2.0 SomeKeyValue pair = new SomeKeyValue(); value.Name = “anonymous”; value.Value = null; // C# 3.0 var value = new SomeKeyValue() { Name = “anonymous”, Value = null, }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 47. Collection Initializers // C# 2.0 List<int> list = new List<int>(); list.Add(1); list.Add(2); // C# 3.0 var list = new List<int> { 1, 2 }; VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 48. Extension Methods static class ComponentExtensions { static void DoSomething( this IComponent component, T arg) { … } } ComponentExtensions.Do(component, arg); component.DoSomething(arg); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 49. Anonymous Types foreach (var value in from row in table select new { Type = row.GetType(), Hash = row.GetHashCode(), }) { Console.WriteLine(“{{ Type = {0}, Hash = {1} }}”, value.Type, value.Hash); Console.WriteLine(value); } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 50. Lambda Expressions // C# 2.0 Func<Type, bool> predicate = delegate(Type value) { return value == default(Type); }; // C# 3.0 Func<Type, bool> predicate = value => value == default(Type); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 51. Query Keywords var q = from c in categories join p in products on c.ID equals p.CID orderby c.ID, p.Price descending group p.Price by c.ID into g let cid = g.Key where Predicate(cid) select g.Average(); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 52. Query Keywords (cont.) var q = categories .Join(products, c => c.ID, p => p.CID, (c, p) => new { c = c, p = p }) .OrderBy(_ => _.c.ID) .ThenByDescending(_ => _.p.Price) .GroupBy(_ => _.c.ID, _.p.Price) .Select(g => new { g = g, cid = g.Key }) .Where(_ => Predicate(_.cid)) .Select(_ => _.g.Average()); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 53. Auto-Implemented Properties // C# 2.0 public Type PropertyName { get { return fieldName; } internal set { fieldName = value; } } // C# 3.0 public Type PropertyName { get; internal set; } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 54. Partial Method Definitions // Generated.Designer.cs partial class Generated { Generated() { OnInitialized(); } partial void OnInitialized(); } // Generated.cs partial class Generated { partial void OnInitialized() { … } } VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 55. Reactive Extensions for .NET Framework 3.5 SP1 VS .NET VS .NET 2003 VS 2005 VS 2008 Rx More LINQ with System.Interactive – Getting Started by Bart De Smet
  • 56. Reactive Extensions Task Parallel Library ∈ .NET Framework 4.0 Observer Design Pattern VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 57. Task Parallel Library System.Collections.Concurrent • ConcurrentBag<T> tbb::concurrent_vector<T> • ConcurrentQueue<T> tbb::concurrent_queue<T> • ConcurrentStack<T> tbb::concurrent_stack<T> • ConcurrentDictionary<TKey, TValue> tbb::concurrent_hash_map<Key, T> VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 58. Task Parallel Library (cont.) System.Threading.Tasks // C# 3.0 ThreadPool.QueueUserWorkItem( callback, state); // C# 4.0 or Rx Task.Factory.StartNew( action, state); VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 59. Observer Design Pattern VS .NET VS .NET 2003 VS 2005 VS 2008 Rx More LINQ with System.Interactive – Getting Started by Bart De Smet
  • 60. Observer Design Pattern (Further reading) Duality of IEnumerable<T> / IObservable<T> Reactive Framework Finally Explained More LINQ with System.Interactive series VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
  • 61. Q&A