Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Tuesday, November 22, 2016

C# Tip - Using the async and await keywords for asynchronous programming

In C#, you can use the async and await keywords for asynchronous programming (such as fetching data from a network, or saving/loading data from files). To understand how to use these 2 keywords, consider the following example:

    async Task DownloadFromWebAsync()
    {
        HttpClient client = new HttpClient();
        Task getStringAsyncTask = 
            client.GetStringAsync("http://www.google.com");
        string content = await getStringAsyncTask;         

        // control is returned to the caller 
        // of the DownloadFromWebAsync() method 
        // and resumed after getStringAsyncTask 
        // is completed    

        return content;
    } 

In the above DownloadFromWebAsync() method , it is first of all prefixed with the async keyword, which indicates that this method contains an asynchronous operation. This method returns a Task result. This represents an asynchronous operation that returns a result of type string:

    async Task DownloadFromWebAsync()

Within this method, we use the HttpClient class to help us connect to the Web:

        HttpClient client = new HttpClient();

In particular, the GetStringAsync() method connects to the specified URL and returns the content of the URL. It returns an object of type Task:

        Task getStringAsyncTask = 
            client.GetStringAsync("http://www.google.com");

Because the GetStringAsync() method could potentially take a long time, and so you need to run it asynchronously. This is achieved by using the await keyword:

        string content = await getStringAsyncTask;

At this point, the GetStringAsync() method will proceed to download the specified URL and control will return to the caller of the DownloadFromWebAsync() method. All statements after this line will only be executed after the GetStringAsync() method returns.

When the GetStringAsync() method returns, the result is passed to content, and the DownloadFromWebAsync() method will now return a string.

To call the DownloadFromWebAsync() method, you would need to use the await keyword. Also, the method from which you are calling the DownloadFromWebAsync() method must also be prefixed with the async keyword, like this:

    private async void button1_Click(object sender, EventArgs e)
    {
        string content = await DownloadFromWebAsync();
    }

Note that the 2 statements:

    Task getStringAsyncTask = 
        client.GetStringAsync("http://www.google.com");
    string content = await getStringAsyncTask;         

Can also be rewritten as:

    string content = await      
        client.GetStringAsync("http://www.google.com");

I hope this simple example makes it easier for you to understand how to use the async and await keywords.

Friday, July 08, 2016

Programming Languages Series of Courses


Friday, September 04, 2015

MOB104 - Writing Cross Platform iOS and Android Apps using Xamarin.Forms and C# - 23 Sep 2015

In this 1-day workshop, you will learn the fundamentals of building cross-platform mobile apps targeting iOS and Android devices using Xamarin.Forms. Using Xamarin Studio or Visual Studio, you can now write iOS and Android apps using your familiar C# language. When you are ready to deploy your apps, the Xamarin compiler will compile your app into the native binary for each platform. The end result is you have a first class application that is optimized for the respective platform that it is compiled for.

Here are some articles on what you can do with Xamarin.Forms:
Getting Started with Xamarin Forms
Using Native Platform Features in Xamarin.Forms Through DependencyService
Providing Location Service Using DependencyService in Xamarin.Forms
Course Fee
S$799 (nett; no GST)
If your company is sponsoring you for the training, your company can enjoy 400% tax deductions/ allowances and/or 60% cash payout for investment in innovation and productivity improvements under the Productivity and Innovation Credit (PIC) scheme. For more details, check out the Productivity and Innovation Credit page. 
Schedules
Start DateEnd DateDetailsCategory
Wed Sep 23 2015 CONFIRMEDWed Sep 23 2015PDF
Venue
Bayview Hotel Singapore
30 Bencoolen Street
Singapore 189621  

Monday, April 20, 2015

New Xamarin Courses!

Due to the popular demand of the Xamarin courses, I have decided to redesign the courses so that they can better fit the needs of developers:

1. MOB102 - 1-Day Writing iOS Apps using Xamarin and C# - S$799
Who should attend?
Developers who are primarily interested in leveraging their C# skill set to build iOS apps. Developers will learn how to encapsulate their business logic in separate DLLs and use them in their iOS apps. DLLs can also be reused in Android apps.

2. MOB103 - 1-Day Writing Android Apps using Xamarin and C# - S$799
Who should attend?
Developers who are primarily interested in leveraging their C# skill set to build Android apps. Developers will learn how to encapsulate their business logic in separate DLLs and use them in their Android apps. DLLs can also be reused in iOS apps.

3. MOB104 - 1-Day Writing Cross Platform iOS and Android Apps using Xamarin.Forms and C# - S$799
Who should attend?
Developers who want to write apps that target Android and iOS platforms. Using a common set of UI elements from Xamarin.Forms, developers will be able to write their apps and run them on iOS and Android devices.

Developers who are interested to develop cross platform mobile apps are strongly advised to take the three courses. Participants who register for the three courses can enjoy a discount course fee of S$2,000 for the three courses. 

Tuesday, November 11, 2014

Building Cross Platform iOS and Android Apps using Xamarin and C# - 14-16 Jan 2015 (OSLO, NORWAY)

In collaboration with ProgramUtvikling, I will be teaching the Writing Cross Platform iOS and Android Apps using Xamarin and Ccourse on the 14-16 Jan 2015 in Oslo, Norway. This is a 3-day course that teaches the fundamentals of iOS and Android programming using Xamarin and the C# language . If you and your team are interest to get into cross platform iOS and Android development, this course provides the most cost effective way to get started! At the end of the course, you will be able to develop applications that runs on both the iOS and Android devices. 


What's more, this course will be taught using the latest version of Xamarin, and it will cover the latest Xamarin Forms, which allows you to build cross platform user interfaces for iOS and Android devices. For this course, you will get a lab-intensive workbook that illustrates the many important concepts of building an iOS and Android app.



Wednesday, October 16, 2013

CS102 – Advanced C# 5.0 - Object-Oriented Programming - 9-10 Dec 2013

Since the release of the Microsoft .NET Framework in July 2000, the C# programming language has gone through a few revisions, with the latest version 5.0. Over the years, the C# language has gained a lot of followers, partly due to its familiar syntax to Java and C. The clear syntax of the language made it easy to learn, and is a popular choice for beginning programmers.


Coupled with Visual Studio, Microsoft’s flagship development environment, developing applications using C# is now available to a wide audience. In this fast-pace 2-day course, attendees will gain a solid foundation in C# programming. In particular, special focus will be placed on Object-Oriented Programming (OOP) using C#.

Topics
Motivations for Object-Oriented Programming (OOP)
   
Classes
    Objects
Interfaces
Inheritance
Delegates and Events
Generics
Language Integrated Query (LINQ)
Named Methods
Optional Parameters
async and await
Advanced Topics
    Threading
    Files and Streams

Course Fee
• S$997 (nett; No GST)

Download course outline and application here.

Dates
• 9-10 Dec 2013 (Mon-Tue)

Venue
Bayview Hotel Singapore
30 Bencoolen Street 
Singapore 189621

Sunday, August 25, 2013

Xamarin Course on 2-4 Oct 2013

In this 3-day workshop, you will learn the fundamentals of building cross-platform mobile apps targeting iOS and Android devices using Xamarin and C#.

Using the Xamarin Studio, you cannow write iOS and Android apps using your familiar C# language. When you are ready to deploy your apps, the Xamarin compiler will compile your app into the native binary for each platform. The end result is you have a first class application that is optimized for the respective platform that it is compiled for.

Topics
• Introduction to Xamarin and Xamarin Studio
• HelloWorld using Xamarin Studio
• Using the emulators and simulator
• Handling Screen Rotations
• User interface Design
• Multi-screen applications
• Files Handling & Data Storage
• Cross-platform Code Sharing for Android and iOS
    o Strategies for cross-platform code sharing
    o Web Services
    o Data Storage

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
2-4 Oct 2013 (Wed-Fri)

Time
9am to 5pm

Fee
S$1,495

Monday, June 24, 2013

Next Xamarin Course - 14-16 Aug 2013 (Wed to Fri)

A big thank you to those who attended the first Xamarin course! And to those of you who asked about the next run, I am happy to announce that the next run is scheduled to run on the 14-16 Aug 2013 (Wed to Fri).

Please note that for this course, you have to bring along a Mac as testing your iOS apps requires a Mac.

For course outline, please click here.

Key Highlights of the Course
* Learn how to write iOS apps using C# and Xamarin.iOS

* Learn how to write Android apps using C# and Xamarin.Android
* Learn how to share common code modules with your iOS and Android apps

You do not need prior knowledge of iOS and Android programming. You just need to know C#!


Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
14-16 Aug 2013 (Wed to Fri)

Time
9am to 5pm

Fee
S$1,495 (nett; GST N.A.)

Monday, June 17, 2013

First Training Provider to Provide Xamarin Studio Training in Singapore


I am super excited to announce that Developer Learning Solutions is the first training provider to provide training on Xamarin Studio in Singapore. If you would like to learn how to create cross platform Android and iOS apps using C#, join us this Wednesday to Friday (19-21 June 2013) for the inaugural run of the course! Hope to see you there!

Sunday, April 28, 2013

Xamarin Tip: Implementing Protocols and Delegates in iOS Apps


If you are familiar with iOS development using Objective-C and are in the process of converting to using C# in Xamarin, here is a common problem you will frequently encounter. How do you implement protocols and delegates in C#? A classic example is that of the UIAlertView class. Using the UIAlertView class, you can display an alert view together with one or more buttons. When the user taps on the button(s), you want to know which button was tapped.

To implement an Objective-C protocol in C#, simply declare a sub-class of the protocol. In the case of the UIAlertView class, the subclass would look like this:

    public class MyAlertDelegate : UIAlertViewDelegate {
        public override void Clicked (UIAlertView alertview,
        int buttonIndex)
        {
            Console.WriteLine(buttonIndex.ToString() +
            " clicked.");
        }
    }

To implement the protocol, create an instance of the MyAlertDelegate class:

        MyAlertDelegate alertDelegate;
        alertDelegate = new MyAlertDelegate();

And then use it together with the UIAlertView object, like this:

        UIAlertView alert =
            new UIAlertView("Hello, World!",
                            "Welcome to Xamarin, ",
                            alertDelegate,
                            "OK",
                            "Cancel");
        alert.Show();

When a button in the alert view is now tapped, a message will be printed in the console window. 

Attending the Xamarin Training in Singapore. Check out this link for more details. 

Thursday, April 25, 2013

CSH101 – 2-Day Object-Oriented Programming using C#


Since the release of the Microsoft .NET Framework in July 2000, the C# programming language has gone through a few revisions, with the latest version 5.0. Over the years, the C# language has gained a lot of followers, partly due to its familiar syntax to Java and C. The clear syntax of the language made it easy to learn, and is a popular choice for beginning programmers.

Coupled with Visual Studio, Microsoft’s flagship development environment, developing applications using C# is now available to a wide audience. In this fast-pace 2-day course,
attendees will gain a solid foundation in C# programming. In particular, special focus will be placed on Object-Oriented Programming (OOP) using C#.

Topics
• Basics of the .NET Framework
• C# language syntax
• Data Types
• Arrays and Collections
• Making Decisions
• Exception Handling
• Motivations for Object-Oriented Programming (OOP)
    o Classes
    o Objects
• Interfaces
• Inheritance
• Delegates and Events
• Generics
• Advanced Topics
    o Threading
    o Files and Streams

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
27-28 Jun 2013 (Thu-Fri)

Time
9am to 5pm

Fee
S$997

New Course - MOB101 – 3-Day Writing Cross Platform iOS and Android Apps using Xamarin and C#

In this 3-day workshop, you will learn the fundamentals of building cross-platform mobile apps targeting iOS and Android devices using Xamarin and C#.

Using the Xamarin Studio, you cannow write iOS and Android apps using your familiar C# language. When you are ready to deploy your apps, the Xamarin compiler will compile your app into the native binary for each platform. The end result is you have a first class application that is optimized for the respective platform that it is compiled for.

Topics
• Introduction to Xamarin and Xamarin Studio
• HelloWorld using Xamarin Studio
• Using the emulators and simulator
• Handling Screen Rotations
• User interface Design
• Multi-screen applications
• Files Handling & Data Storage
• Cross-platform Code Sharing for Android and iOS
    o Strategies for cross-platform code sharing
    o Web Services
    o Data Storage

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
19-21 Jun 2013 (Wed-Fri)

Time
9am to 5pm

Fee
S$1,495.
Register before 1 June to enjoy a S$100 early bird discount!