C# 4.0 Language Features: Alexandru Ghiondea Software Developer Engineer in Test C# Compiler
C# 4.0 Language Features: Alexandru Ghiondea Software Developer Engineer in Test C# Compiler
Alexandru Ghiondea
Software Developer Engineer in Test
C# Compiler
[email protected]
March 31st 2010
C# 4.0 Language
Alexandru Ghiondea
Software Developer Engineer in Test
C# Compiler
[email protected]
The Evolution of C#
C# 4.0
Dynamic
Programming
C# 3.0
Language Integrated
Query
C# 2.0
Generics
C# 1.0
Managed Code
C# 4.0 Language Innovations
− Dynamically Typed Objects
− Optional and Named Parameters
− Improved COM Interoperability
− Co- and Contra-variance
.NET Dynamic Programming
IronPython IronRuby C# VB.NET Others…
.NET object
object calc = GetCalculator();
Type calcType = calc.GetType();
object res = calcType.InvokeMember("Add",
BindingFlags.InvokeMethod, null,
new object[] { 10, 20 }); Dynamic Language object
int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator();
object res = calc.Invoke("Add", 10, 20);
int sum = Convert.ToInt32(res);
Statically typed
to be dynamic dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
((Excel.Range)xl.Cells[1,1]).Value2 = “ID”;
xl.Cells[1,1].Value2 = “ID”;
Non-optional must
be specified
xlChart.ChartWizard(cellRange.CurrentRegion, Constants.xl3DBar,
PlotBy: Excel.XlRowCol.xlColumns,
SeriesLabels: 2,
CategoryLabels: 1,
HasLegend: false,
Title: xlSheet.Name);
doc.SaveAs(ref fileName,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
doc.SaveAs("Test.docx");
Under the cover
− The default value for a parameter is
encoded with a DefaultParameterValue
attribute
− The compiler inserts that value if a value is
not specified for that parameter
− If a default value is not specified we will use
default(type)
− For COM, the compiler will pass in Type.Missing