$30 off During Our Annual Pro Sale. View Details »

Introduction to C#

Introduction to C#

A basic introduction to the C# programming language, presented at a StudentGuru Patras event in November 2012

Konstantinos Goutsos

November 14, 2012
Tweet

More Decks by Konstantinos Goutsos

Other Decks in Programming

Transcript

  1. Konstantinos Goutsos
    Undergraduate student – ECE Department
    StudentGuru Patras Member

    View Slide

  2. Object-Oriented
    Programming

    View Slide

  3. objects
    properties
    Object-Oriented Programming
    methods
    classes inheritance
    interfaces
    the basics

    View Slide

  4.  Better approach to the real world
     Modularity
     Data Encapsulation
     Code re-use
     Pluggability and debugging
    Why use Object-Oriented Programming?

    View Slide

  5. color
    manufacture
    date
    Car
    speed
    brake() changeGear()
    accelerate()
    our sample class
    gear

    View Slide

  6. Car
    class implementation in C#

    View Slide

  7. Visual C# 2012

    View Slide

  8. automatic
    memory
    handling lots of libraries
    Why use Visual C#
    most code
    written for you
    desktop
    applications
    internet
    applications
    cross-platform
    object-oriented
    programming
    web+cloud
    services
    embedded
    systems

    View Slide

  9. Variables
    types & declaration
    • Supported types: integers, doubles, strings, dates
    and many more
    • Declaration: [type] name = [value];
    • Example: string name="Konstantinos";
    • Important: Assign with one = compare with two ==
    • Don‘t forget to initialize your variables!

    View Slide

  10. • Declaration:
    [type][] name= {value, value, ….};
    • For example:
    int[] numbers={0,1,2,3};
    • Element reference: array[index]=5;
    • Memory is automatically allocated and cleaned
    Variables
    arrays

    View Slide

  11. • Same logic as in mathematics:
    = 22 + 3 + 5
    • Function declaration:
    [type] function_name ([type] arg1, [type] arg2,…)
    {
    statements;
    }
    Functions and methods
    the basics

    View Slide

  12. Control statements
    if clauses
    • if (condition)
    statement1;
    else
    statement2;
    • if (condition1)
    statement1;
    else if (condition2)
    statement2;
    else
    statement3;
    Example
    int age;
    boolean legalAge;
    if (age>=18)
    legalAge=true;
    else
    legalAge=false;

    View Slide

  13. switch (expression)
    {
    case 1:
    Console.WriteLine("Case 1");
    break;
    case 2:
    Console.WriteLine("Case 2");
    break;
    default:
    Console.WriteLine("Default case");
    break;
    }
    Control statements
    switch statement

    View Slide

  14. for (int i = 1; i <= 5; i++)
    {
    Console.WriteLine(i);
    }
    int[] array={3,7,1,9};
    foreach(int num in array){
    Console.WriteLine(num);
    }
    Loop statements
    for and foreach

    View Slide

  15. while (condition)
    {
    Console.WriteLine("StudentGuru rocks!!");
    }
    int i=2012;
    do{
    Console.WriteLine(i);
    } while (condition)
    Loop statements
    while and do

    View Slide

  16. • .NET Framework 4.5 support
    • Simpler asynchronous/threaded programming
    with the async and await keywords
    • Quicker debugging with Caller Information
    • Windows Store application support
    What’s new in Visual C# 2012

    View Slide

  17. Visual Studio 2012

    View Slide

  18. • Support for Visual C#, Visual Basic, Visual F#,
    C, C++, ASP.NET, XNA
    • Complete development environment for major
    platforms including Windows desktop,
    Windows Store, Windows Phone, ΧΒox
    • Provides all the tools you might need to create
    pro-level applications
    Visual Studio

    View Slide

  19. • Download the at: msdn.upatras.gr
    • Login with your department credentials: eceXXXX
    or ceidXXXX
    Get Visual Studio 2012
    for free

    View Slide

  20. • New look and feel including a dark theme (yay!)
    • Better faster IntelliSense
    • Support for .NET Framework 4.5 and Visual C#
    2012
    • Ability to develop for Windows Store and Windows
    Phone 8
    • Blend for Visual Studio included
    Key new features

    View Slide

  21. Web Browser Demo

    View Slide

  22. • Microsoft Developer Network:
    msdn.microsoft.com
    • Visual C# in Visual Studio resources:
    http://bit.ly/OJFzDr
    • Active community at StackOverflow
    • StudentGuru: www.studentguru.gr
    • Contact us!!
    Visual C# Resources

    View Slide