C#

Switch URL to Youtube video, Switch URL to Hyperlink using c#

02 July 2011 |

a friend of mine (who is not a developer) has told me that facebook is somehow affiliated with youtube and his reason was that if you type a video URL in the post box in facebook it automatically appears as video it took me 10 minutes to build this demo, this demo takes a block of text “post text ” which presumably includes a youtube URL and turns it into a youtube video in a webpage   1: private const string FIND_URL_REGEX = "http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?"; ...

webclient downloading content files from an https ssl

05 October 2009 |

i was using the webclient object to download files from a website and my application worked fine. my client decided to add an SSL certeficate to the website and has required me to change my code to request the file through https instead of http all i had to do was change the URL to have https:// instead of http:// but when i first tried the code. i got this exception: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to...

yield in c

25 February 2008 |

i've been trying to explain the keyword yield to a friend of mine for more than an hour and he did not get it. but finally when i typed in this example he finally did 1: class enu :IEnumerable 2: { 3: public IEnumerator GetEnumerator() 4: { 5: yield return 1; 6: ...

delegates to linq passing logic as a parameter part i

08 February 2008 |

it's normal to pass data to a function just thow in a parameter of the type of data you want to pass and ur set public int add (int i,int u ){ return i+u;}   now think in a different way, u now want to build a set of operations that the user can choose from now what you need is to build a function that would take the user's input and the operation as parameters and put them together... for instance he has a set of .. customers if you will and he wants to have them filtered...

have u ever needed to extend a string [extension methods]

27 December 2007 |

well it's not inheritable by default so you can not extend it. that used to be the case before c# 3.0 now you can specify all the functionality that you need in an Extension Method. problem lies in that the extension method needs to access the instance of the object you are extending well, it goes like this 1- first you declare a static class with ur static extension method an extension method is defined by the first parameter refering to the instance of the object it's going to extend using the Keyword this (note to...

object and collection initializers

26 December 2007 |

well also one of the nicest features in c# 3.0 is the object initializers well we used to do this 1: Employee emp = new Employee(); 2: emp.FirstName="Amir"; 3: emp.LastName="Magdy"; 4: emp.Title = "Mr."; i actually hated writing this previous snippet now in c# 3.0 we do this 1: var emp = new Employee {FirstName="Amir",LastName="Magdy",Title="Mr."}; u c that's just one line it's really nicer now that u don't have to write the type name twice as in line 1 first snippet u just type var also it's way nicer when...

auto implemented properties

24 December 2007 |

C# 3 comes with a very nice feature (not undermining the power of lambda expressions and Linq), just this one shows how nice the language has evolved into   1: class Employee 2: { 3: public string firstName { get; set; } 4: } you see the previous code will act as a full blown property that maintains its instance value internally the compiler creates a member and maintains the value for the property and u can use it in the usual way 1: var emp...