Extension method for IEnumerable to get a deep copy cloned object.

When we assign a List object to another it does a shallow copy, and making a change into copied object reflects in source object as well. This does not serves the purpose, thus finding a ways is through extension methods.

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Csharp
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.  
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             List<string> abc = new List<string>();
  18.             abc.Add("a");
  19.  
  20.             var newList = AddAlphabet(abc);
  21.  
  22.             Console.WriteLine(abc.Count);
  23.             Console.WriteLine(newList.Count);
  24.             Console.ReadLine();
  25.         }
  26.  
  27.         private static List<string> AddAlphabet(List<string> abc)
  28.         {
  29.             List<string> _abc = abc;
  30.             _abc.Add("d");
  31.             _abc.Add("e");
  32.             return _abc;
  33.         }
  34.  
  35.  
  36.         
  37.     }
  38. }

This produces following result in output

3

3

Changing the code and added an extension method will result in proper result that I expected earlier.

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Csharp
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.         public static IEnumerable<T> Clone<T>(this IEnumerable<T> collection) where T : ICloneable
  14.         {
  15.             return collection.Select(item => (T)item.Clone());
  16.         }
  17.  
  18.         static void Main(string[] args)
  19.         {
  20.             List<string> abc = new List<string>();
  21.             abc.Add("a");
  22.  
  23.             var newList = AddAlphabet(abc.Clone<string>().ToList());
  24.  
  25.             Console.WriteLine(abc.Count);
  26.             Console.WriteLine(newList.Count);
  27.             Console.ReadLine();
  28.         }
  29.  
  30.         private static List<string> AddAlphabet(List<string> abc)
  31.         {
  32.             List<string> _abc = abc;
  33.             _abc.Add("d");
  34.             _abc.Add("e");
  35.             return _abc;
  36.         }
  37.  
  38.  
  39.         
  40.     }
  41. }

This produces following result in output

1
3

We notice that it does not change the original value of source.

Webinar : Windows Azure Basics

I presented this webinar online on 10th Feb, 2014. I hope it would have been a fun experience for people.

This webinar followed the following topics relating to Windows Azure:

– Windows Azure Basics
– Windows Azure Storage
– Tools and Technology
– Windows Azure Mobile Services
– How to build apps using Windows Azure Mobile Services
– Introduction to Azure portal
– Different Services offered by windows Azure

Some key links and notes:

http://www.windowsazure.com

To get PublishSetting profile visit the link below:
•https://windows.azure.com/download/publishprofile.aspx

A publishsettings file will be downloaded and the file name will be in given format:

-credentials.publishsettings

Some examples of how to do good programming in C#


foreach( i=0; i < getdata (); i++) { // }

should be

var data=GetData();
foreach( i=0; i < data ; i++) { // }

The call to GetData() is reduced to one, and thus increased performance overheads.

Another example:

///////////////////////////////////////////////////////////


if (IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “”)
{
IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, “true”);
}
else
{
IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, “”);
}


could be written as

IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “” ? “true” : “”);

could be written as

var loadedStringValue=IsolatedStorageWrapper.LoadString(“ShowTipsAndTricks”) == “” ? “true” : “”;

IsolatedStorageWrapper.SaveString(“ShowTipsAndTricks”, loadedStringValue);


could again be written as

var loadedStringValue = IsolatedStorageWrapper.LoadString( “ShowTipsAndTricks” ) == “” ? “true” : “”;
IsolatedStorageWrapper.SaveString( “ShowTipsAndTricks” , loadedStringValue );

Online Video Conference Event On Microsoft Visual C# 2012

Education is vital to a sustainable social and economic progress. Microsoft believes that when high-quality education is accessible, relevant and meaningful, citizens of all ages will have real opportunities to develop the skills they need to succeed. Keeping this in mind, Microsoft and Higher Education Commission, Pakistan (HEC) partnered in the form of an Educational Alliance. The objective is to drive the Local Software Economy and enhance capacity building.

Microsoft and HEC has organized a Training Session on Microsoft Visual C# 2012, the training comprises of 1 hours long session organized for Students. The objective of this training session is to empower and train on latest technologies and provide with the relevant mentorship and technical support.

Microsoft Visual Studio 2012 is loaded with new capabilities for Windows 8, the web, SharePoint, mobile, and cloud development—as well as the application management lifecycle tools you need to break down team barriers and reduce cycle times to deliver value continuously. You’ll even find a redesigned UI to streamline everyday tasks and kick your productivity into gear.
Event Details:
Event: Microsoft Visual C# 2012
Date: Friday, 20th September, 2013
Time: 10:30 AM – 11:30 AM
Location: Online at Video Con. Facility of HEC
Presenter: Ali Sufyan Butt

Universities Online:

10+ universities were connected live

130+ Microsoft student partners

100+ MSDN partners were also online for the session

  • University of Karachi
  • NUML
  • University of Azad Jammu Kashmir
  • UET Taxila
  • International IslamicUniversity
  • AIR University
  • Kohat University of Science and Technology
  • GCU Faislabad, GCU Lahore
  • Lahore College for Women
  • AIOU

The session covered advance C# concepts in .net framework 4, 4.5 and upcoming async features. The session was both theoretical and practical at the same time.

C# – Session delivered at Higher Education Commission of Pakistan-HEC

An Online Session Broadcasted live in HigherEducationCommissionPakistan for All the Public Universities in Pakistan.

The session was delivered by Ali Sufyan Butt, and was attended by major public universities online over Live Video Conferencing. Approximately, 150+ students joined the event.

Pictures can be seen here Click to load pictures

Universities Joined Us:
– UNIVERSITY OF KARACHI
– Numl
– University of Azad Jammu and Kashmir (UAJK)
– University of Engineering & Technology (U.E.T) Taxila
– International Islamic University, Islamabad (IIUI)
– Air University
– Kohat University of Science & Technology (KUST)
– GC University, Faisalabad.
– GC University, Lahore.
– Lahore College For Women University – Official
– AIOU

Topics Covered Were:

C# Fundamentals

Introduction to C#
DEMO containing Below:
– Classes and objects
– Types
– Events
– Properties
– Methods
– Exceptions
– Lamdas. Action and Func

C# 4.0

– Parameters
– Co and Contravariance
– Dynamic
– New Compiler options

Some features

– LINQ
– Better C# Coding Practices

C# 5
– Asynchronous Programming in C#
– Practical demo