New features on c# 5,0

Microsoft released c# 5.o and we will check out some good features on this tutorial.

Two Way Binding

comboBox.Text :=: textBox.Text;

:=: operator helps us to  bind data in two way, its means when combobox text change it will effect to textbox value and same for opposite.


Better Switch Case

New switch case is more smart now.We are able to check some conditions on case statement.

switch(object1)
{
   case string.IsNullorEmpty(object2):
   case object12.ToUpper():

}

Asynchronous  Programming

This is very cool features and will help us in many case, before async we need to manage all process initially with callback functions but now async and await keywords will help us. We are using await keyword to say this method works asynchronous and async keyword give us an information process.

public async Task<IEnumerable<Product>> GetProductList()
{
 HttpClient client = new HttpClient();
 Uri address = new Uri("http://api.webron.com.tr/");
 client.BaseAddress = address;
 
 HttpResponseMessage response = await client.GetAsync("GetProducts");
 
 if (response.IsSuccessStatusCode)
 {
 var list = await response.Content.ReadAsAsync<IEnumerable<Product>>();
 return list;
 }
 else
 {
 return null;
 }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *