4. 책임연구원
2010/2011, 마비노기2
2006/2009, 마비노기 영웅전
테크니컬 디렉터
2004/2005, 마비노기
2003/2004, 프로젝트 T2
[ɡ̊ɪm̚ ʨæːsɤk̚]
/ɡim ɟɛːzʌɡ/ 2001/2003, Oz World
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. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio .NET Rainer
.NET Framework 1.0 / C# 1.0
7. 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
8. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Common Type System
Primitive Types
Field
Method
Property
Event
9. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Primitive Types
Byte Boolean
Int16 Char
Int32 Decimal
Int64 IntPtr
Single
Double String
10. 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;
11. 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
12. 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();
};
13. 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);
14. 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);
15. 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; }
}
16. 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);
};
17. 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;
18. 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();
19. 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);
20. 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;
}
}
21. 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));
}
22. 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() { }
};
23. 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
24. 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; }
25. 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
{
…
};
26. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Delegates
Closures or managed functors
Calling conventions:
• cdecl
• stdcall
• fastcall
• thiscall
• function object
27. 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);
28. 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
29. 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
30. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio .NET 2003 Everett
.NET Framework 1.1 / C# 1.2
31. 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
32. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio 2005 Whidbey
.NET Framework 2.0 / C# 2.0
33. 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
Visual Studio® 2005
34. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
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>
35. 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;
}
}
36. 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
{ … }
37. 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);
38. 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);
};
39. 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();
}
}
40. 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; }
}
41. 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);
42. 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;
43. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Visual Studio 2008 Orcas
.NET Framework 3.5 / C# 3.0
44. 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
Visual Studio® 2008
45. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
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) };
46. 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,
};
47. 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 };
48. 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);
49. 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);
}
50. 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);
51. 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();
52. 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());
53. 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; }
54. 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() { … }
}
55. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
More LINQ with System.Interactive – Getting Started by Bart De Smet
Reactive Extensions for .NET Framework 3.5 SP1
56. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Reactive Extensions
Task Parallel Library ∈ .NET Framework 4.0
Observer Design Pattern
57. 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>
58. 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);
59. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Observer Design Pattern
More LINQ with System.Interactive – Getting Started by Bart De Smet
60. VS .NET VS .NET 2003 VS 2005 VS 2008 Rx
Observer Design Pattern
(Further reading)
Duality of IEnumerable<T> / IObservable<T>
Reactive Framework Finally Explained
More LINQ with System.Interactive series