Coding Geek

A blog by Nadeem Iqbal

July 2010 - Posts

C# 4.0 - New Feature I Like Most

String.IsNullOrWhiteSpace

Previous version of C# contain method String.IsNullOrEmpty which checks whether string is empty or null. If String only contain white spaces (it's also a case of empty string) you will be required to add an additional trim() function to handle it. But if you will use trim() on an null string, it will throw exception so you will be required to write few lines of code for it. But new function in string class

The new String.IsNullOrWhiteSpace method indicates whether a string is null, empty, or consists only of white-space characters.


Posted: Jul 23 2010, 04:06 PM by niqbal | with 4 comment(s) |
Filed under: , , , ,
Silverlight - Convert List to ObservableCollection

 In Silverlight, you will bind the controls such as List/Grid with Observable collection so that any change in the collection automatically reflected on the control.

Often you will be required to convert the List to an observable collection but there isn't exist any method which automatically do so in Silverlight. Moreover, WCF service can only return IEnumerable collection which you may want to convert to the ObservableCollection. So, here is generic way to convert any List to Observable collection;

                        //create an emtpy observable collection object


            var observableCollection = new ObservableCollection<T>();

 

            //loop through all the records and add to observable collection object

            foreach (var item in enumerableList)

                observableCollection.Add(item);

 

            //return the populated observable collection if being used in function

            return observableCollection;

 I hope this will help you ... Cheers:)

 

More Posts