Mittwoch, 7. Oktober 2015

From Java to C# - A few notes


  • You might instantiate a generic class like a normal array:
    List<T> mylist = new List<T>() { t1, t2, t3, ..., tn};
  • LINQ - Language Integrated Query
    • Queries for different DBs, XML, Generics
  • Properties
    • These are easy written accessors
    • Futhermore an easy possiblity to convert information
      • e.g. we store seconds in our time class
      • you might write a property which allows you to simulate an other variable, like hours
        which still relays on the seconds.
      • public string Name
        {
          get { return ...; }
          set { ... = value;}
        }
  • Only functions noted with the keyword virtual might be overwritten.
  • Override is a keyword, not an annotation
  • Javas super is C#s base
  • You must to append an f to your float
    • float f = 3.141f
  • There is a special keyword var
    • var is a type which is determined at compile-time. So it can't change on run-time!
    • var v = (new List<int>() {1,2,3})[0];
      • v has the type int now
    • You might use var in foreach
  • foreach (Type t in Collection) is javas for (T t : Collection)
  • All types are objects!
    • There are two subtypes:
      • Valuetypes
      • Referencetypes
  • There is not multiple inheritance.
  • You implement interfaces and super classes in the same way:
    • class sub : super
      {
        // ...
      }
    • class implementation : interface
      {
        // ...
      }
  • There a different types of lambdas:
    • Action<T1, ..., Tn>(...) which maps on void
    • Func<T1, ..., Tn, Tresult>(...) which maps on given type Tresult
  • Futhermore there are two keywords for easy threading:
    • await
    • async




Keine Kommentare:

Kommentar veröffentlichen