• Save
Intro to .NET and Core C#
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,450
On Slideshare
1,450
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Intro  to  .NET  and  Core  C#   Jussi  Pohjolainen  
  • 2. .NET  Framework  •  So=ware  framework  developed  by  MS   –  Runs  primarily  on  windows  •  Benefits   –  Support  for  numerous  programming  languages   –  Language  integra2on   •  You  can  mix  different  languages   –  Comprehensive  base  class  library   –  Apps  runs  on  top  of  virtual  machine   •  Support  for  other  operaIng  systems  (in  theory)   –  Great  tools:  Visual  Studio  
  • 3. Common  Language  Infrastructure  (CLI)  
  • 4. CLI  •  CLI  is  an  open  specificaIon  that  describes   executable  code  and  runIme  environment  •  CLI  is  core  of   –  Microso=  .NET  Framework   –  Mono  (Open  Source)   –  Portable.net  (Open  Source)    
  • 5. CTS,  CLS,  CIL  •  Common  Type  System  (CTS)   –  A  set  of  data  types  and  operaIons  that  are  share  by   all  CTS-­‐compliant  programming  languages,  such  as  C#   and  VB  •  Common  Language  SpecificaIon  (CLS)   –  Set  of  base  rules  to  which  any  language  targeIng  the   CLI  should  conform.    •  Common  Intermediate  Language  (CIL)   –  Intermediate  language  that  is  abstracted  from  the   plaTorm  hardware  (In  Java:  class)  
  • 6. Mono:OSX  »  C#  File  
  • 7. Mono:OSX  »  Building  
  • 8. Mono:OSX  »  Running  
  • 9. Developer  Command  Prompt  for  VS2012  
  • 10. Common  Language  RunIme:  Mac   Dropbox  –   folder  
  • 11. Common  Language  RunIme:  Win   And  run   the  .exe  in   Windows!  
  • 12. Compiling  Several  Files  in  C#  C:CodeSample> csc /main:A /out:example.exe A.cs B.csC:CodeSample> example.exe Hello World from class AC:CodeSample> csc /main:B /out:example.exe A.cs B.csC:CodeSample> example.exe Hello World from class B
  • 13. Open  Source  DistribuIons  •  h_p://www.mono-­‐project.com  •  h_p://www.gnu.org/so=ware/dotgnu/ pnet.html  
  • 14. IDEs  •  You  can  compile  and  run  apps  in  commandline   –  Several  good  text  editors:  notepad++,  sublime   text,  emacs  •  SharpDevelop   –  Open  source  IDE  for  .NET  •  MS  Visual  Studio  Express   –  Object  browsing  tools,  GUI  ediIng,  Intellisense  
  • 15. Visual  Studio  
  • 16. C#  •  C#  is  very  similar  to  Java   –  C#,  Java,  ObjecIve-­‐C  and  C++  are  a  member  of  C   family  of  programming  languages  •  C#  provides  more  syntax  than  Java,  although   Java  7  (and  upcoming  8)  is  “catching  up”  •  In  this  course,  we  focus  on  C#  (instead  of   other  CIL  complient  languages)  
  • 17. About  Namespaces  •  Libraries  give  you  exisIng  code  to  use  •  In  .NET:  namespaces   –  Using  System.CollecIons;   –  Using  System.IO;   –  Using  System.XML;  •  System  is  not  the  root,  you  may  find  namespaces   like  Microso=  that  provides  services  unique  to   Windows  (can’t  run  on  other  systems)  •  Namespaces  are  linked  to  files,  assemblies.  One   assembly  (mscorlib.dll)  can  contain  number  of   namespaces.  
  • 18. Assemblies:  c:/windows/assembly  
  • 19. Adding  a  Assembly  in  VS  •  When  wriIng   –  Using  System.Windows.Forms;  •  This  uses  a  assembly   System.Windows.Forms.dll  •  You  must  add  this  as  a  reference  in  your   project!  •  How?   –  In  VS:  SoluIon  Explorer  >  References  >  Add   Reference  
  • 20. C#  using System;class MyApp{ public static void Main() { Calculator c = new Calculator(); Console.Write(c.calculate(5,5)); }}class Calculator { public int calculate(int a, int b) { return a + b; }}
  • 21. Ildasm.exe:  examine  the  CIL  
  • 22. About  Windows  8  •  Visual  Studio  2012  provides  templates  for  Win   8  app  development  •  EnIrely  new  runIme:  Windows  Run2me   (WinRT)  •  New  namespaces,  starIng  with  Windows•  App  development  very  similar  to  building   a  .NET  app:  can  be  constructed  using  C#,   visual  basic,  JS  or  C++  •  Heavy  usage  of  XML-­‐based  grammar  XAML
  • 23. .NET  Role  under  Win8  •  In  addiIon  of  using  Windows.*  namespaces   you  can  use  large  subset  of  .NET  plaAorm  •  We  are  not  focusing  on  this,  but  exclusively   on  .NET  
  • 24. VISUAL  STUDIO  TIPS  
  • 25. Visual  Studio  Tips  •  Refer  to  external  assemblies?   –  VIEW  >  SoluIon  Explorer  •  UIliIty  for  invesIgaIng  assemblies   –  VIEW  >  Object  Browser  UIlity  •  Project  properIes?   –  VIEW  >  SoluIon  Explorer  >  ProperIes  •  Class  Tree  View?   –  VIEW  >  Class  View  
  • 26. Code  Refactoring  and  Snippets  •  Right  click  on  code  and  choose  refactor   –  Extract  method   –  Encapsulate  Field   –  Extract  Interface   –  …  •  When  wriIng  code,  VS  make  suggesIons.   When  finding  the  right  one,  press  tab  twice.   –  Press  esc  to  exit  
  • 27. DocumentaIon  •  .NET  Framework  4.5  documentaIon  available   online:   –  h_p://msdn.microso=.com/library   –  Use  the  tree  hierarchy  leE  to  navigate  
  • 28. Almost  the  Same  but  Not  Quite  C#  
  • 29. Keywords  •  Single  rooted  class  hierarchy:  all  objects   inheritate  System.Object  •  Almost  every  keyword  in  Java  can  be  found   from  C#   –  super -> base –  instanceof -> is –  import -> using –  extends / implements -> :•  Otherwise,  pre_y  much  the  same  
  • 30. Memory  Handling  and  RunIme  •  Memory  Handling   –  Most  objects  in  C#  to  heap  using  new   –  CLR  handles  garbage  collecIons  •  RunIme   –  C#  is  compiled  to  intermediate  langage  (IL)   –  IL  runs  on  top  of  CLR   –  IL  code  is  always  naIvely  compiled  before  running  
  • 31. using System;class Program{ static void Main(string[] args) { Console.WriteLine("Hello"); Console.ReadLine(); }}
  • 32. using System;class Program{ static int Main(string[] args) { Console.WriteLine("Hello"); Console.ReadLine(); return -1; }}
  • 33. using System;class Program{ static int Main() { Console.WriteLine("Hello"); Console.ReadLine(); }}
  • 34. System.Console  •  WriteLine(),  ReadLine()  •  Beep()  •  BackgroundColor  •  ForegroundColor  •  Title  •  WindowHeight  /  Width  /  Top  /  Le=  •  Clear  
  • 35. Formatng  Console  Output  •  Supports  prinT()  statement  of  C.   –  Console.WriteLine(“Hello  {0}!  You  are  {1}  years  old”,   userName,  userAge);  •  Can  use  formatng   –  //  000099999   –  Console.WriteLine(“{0:d9}”,  99999);   –  c,  format  currency   –  d,  format  decimal  numbers   –  f,  format  fixed  point    •  Can  be  used  also  in  Strings:   –  string  message  =  string.Format(“{0:d9}”,  99999);  
  • 36. Data  Types  •  Datatypes  are  “snippets”  for  full  blown  types   in  namespaces!  •  bool  =>  System.Boolean  •  byte  =>  System.Byte  •  short,  int,  long,  char,  float,  double,  decimal   (128  bit),  string,  Object  •  So  this  works!   –  Console.Write(12.toString());  
  • 37. Members  of  Datatypes  •  int.MaxValue  •  int.MinValue  •  double.maxValue  •  double.minValue  •  char.isDigit(myChar)  •  char.isLe_er(myChar)  •  bool  b  =  bool.Parse(“true”);  •  double  d  =  double.Parse(“99.9”);  
  • 38. String  •  Length  •  Compare()  •  Equals()  •  Format()  •  Insert()  •  Remove()  •  Replace()  •  Trim()…  
  • 39. VerbaIm  Strings  String longstring = @”this is a very long string as you can see”;Console.WriteLine(longstring);
  • 40. Comparing  •  Usually  we  compare  memory  addresses   –  object1  ==  object2  •  When  using  strings,  this  is  not  the  case.  You   can  compare  strings  like  this  (unlike  in  Java)   –  string1  ==  string2  
  • 41. Immutable  •  Strings  are  immutable!  Once  assigned  it   cannot  be  changed..   –  String  newString  =  original.toUpper();  •  Even  in  here   –  string  s1  =  “a”;   –  s1  =  “b”;  •  A  new  string  is  created!  •  When  use  of  heavy  textual  data,  don’t  use   strings.    Use  StringBuilder.  
  • 42. Implicitly  typed  variables  •  Usually  we  do  this   –  int  a  =  5;   –  bool  b  =  true;  •  But  we  can  do  also   –  var  a  =  5;   –  var  b  =  true;  •  Why?  Think  of  this:   –  var  c  =  SomeMethod();  
  • 43. C#  For  each  string [] array = {“a”, “b”, “c”};foreach(string c in array) { Console.WriteLine(c);}