tag:blogger.com,1999:blog-64332176462263590842024-03-13T12:01:29.994-07:00Tip Of The DayWhat you Learned Today?Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.comBlogger36125tag:blogger.com,1999:blog-6433217646226359084.post-75488781815260167172011-06-06T19:14:00.000-07:002011-06-06T19:16:51.463-07:00Lookup in .Net 3.5 and aboveIf you want to use a Dictionary type of collection with duplicate key values you can go with Lookup<br /><br />more details read: <a href="http://msdn.microsoft.com/en-us/library/bb460184.aspx">http://msdn.microsoft.com/en-us/library/bb460184.aspx</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-26253643999408835052011-05-25T01:18:00.001-07:002011-05-25T01:18:34.648-07:00Registry Hacks to Make Your PC Fasterhttp://www.pcworld.in/how-to/6-registry-hacks-make-your-pc-fasterAnishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-91910496046782059662011-05-23T01:15:00.000-07:002011-05-23T01:16:49.129-07:00Latest way of debugging using Debugger CanvasThere is a latest way of debugging in VS please read <a href="http://blogs.msdn.com/b/kaelr/archive/2011/05/21/introducing-debugger-canvas.aspx">this</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-2536197366234247162011-05-19T12:48:00.000-07:002011-05-19T12:50:22.848-07:00How to Add Checkbox to Excel in office 2007Here is a good link: <a href="http://www.ehow.com/how_6209662_create-check-box-excel-2007.html">http://www.ehow.com/how_6209662_create-check-box-excel-2007.html</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-19729645508141652612011-05-18T10:34:00.000-07:002011-05-18T10:39:10.907-07:00Lazy in C#If you want to initialize a class as lazy Initialization you can go with<a href="http://msdn.microsoft.com/en-us/library/dd642331.aspx"> Lazy<t></t></a> key word.<br /><br />Lazy<expensive> _expensive = new Lazy<expensive><br />(() => new Expensive(), true);<br /><br />Note: If you pass true as parameter,it will be thread safe else as false, it will not be thread safe.<br /><br /> If for a single -thread or single ton class Lazy is best<br /></expensive></expensive>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-89179682969315802592011-05-18T10:00:00.000-07:002011-05-18T10:12:49.327-07:00If you want to return a query with Default if its Empty?If you want to return a query with default value if it is empty you can go with <a href="http://msdn.microsoft.com/en-us/library/bb355419.aspx">DefaultIfEmpty</a><br /><br />void Main()<br />{<br /> Coder coder = new Coder("Jon");<br /> <br /> List<coder> coderCollection = new List<coder>()<br /> {<br /> new Coder("Anish"),<br /> new Coder("marokey"),<br /> };<br /> <br /> var result = coderCollection.Where(r => r.Name == "Pat").DefaultIfEmpty(coder);<br /> <br />}<br /><br />// Define other methods and classes here<br />class Coder<br />{<br /> public string Name;<br /> <br /> public Coder(string Name)<br /> {<br /> this.Name = Name;<br /> }<br />}<br /></coder></coder>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-88745862348806288152011-05-18T08:50:00.000-07:002011-05-18T08:58:14.800-07:00Order by with out CultureIf you want to do some operations without any culture you can do with the help of <a href="http://msdn.microsoft.com/en-us/library/system.stringcomparer.ordinal.aspx">StringCompare.Ordinal</a> or <a href="http://msdn.microsoft.com/en-us/library/system.stringcomparer.ordinalignorecase.aspx">StringCompare.OrdinalIgnoreCase</a>.<br /><br />void Main()<br />{<br /> string[] nonCulture = { "äax", "ääü", "äbü" };<br /> <br /> IEnumerable<string> orderNonCulture = nonCulture.OrderBy( r => r, StringComparer.Ordinal);<br /> <br /> orderNonCulture.Dump();<br />}<br /></string>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-27596050208821280322011-05-16T02:40:00.000-07:002011-05-16T03:46:46.673-07:00Type Property in C#If want to know type is IsArray or IsInterface you can go with <a href="http://msdn.microsoft.com/en-us/library/1ek3kwtc.aspx">Type Properties</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-39410884577712191372011-05-15T09:58:00.000-07:002011-05-15T10:03:36.514-07:00Semaphore and SemaphoreSlimIf need to restrict number of thread, can go with<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px; text-align: left; "><span style="font-weight: bold;"> </span><a href="http://msdn.microsoft.com/en-us/library/z6zx288a.aspx">Semaphore</a><span style="font-weight: bold;">.<br /><br /></span>Here is the example<br /><br />class TheClub // No door lists!<br />{<br />static SemaphoreSlim _sem = new SemaphoreSlim (3); // Capacity of 3<br />static void Main()<br />{<br />for (int i = 1; i <= 5; i++) new Thread (Enter).Start (i);<br />}<br />static void Enter (object id)<br />{<br />Console.WriteLine (id + " wants to enter");<br />_sem.Wait();<br />Console.WriteLine (id + " is in!"); // Only three threads<br />Thread.Sleep (1000 * (int) id); // can be here at<br />Console.WriteLine (id + " is leaving"); // a time.<br />_sem.Release();<br />}<br />}<br /><br />SemaphoreSlim is introduced in .Net 4.0 and is much faster and simple<span style="font-weight: bold;"><br /></span></span></span>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-6138507537813820142011-05-15T09:26:00.000-07:002011-05-15T09:32:31.281-07:00?? Operator used in LinqHere is the Msdn link for<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left;font-family:'Segoe UI',Verdana,Arial;font-size:13px;" ><span style="font-weight: bold;"> <a href="http://msdn.microsoft.com/en-us/library/ms173224.aspx">?? Operator</a><br /><br /></span>if need to order by a query which need to orderby column1 if not null, if null orderby column2<br /><br />void Main()<br />{<br /> <br /> List<order> orderList= new List<order>()<br /> {<br /> new Order(1, 4),<br /> new Order(null,6),<br /> new Order(2,5),<br /> new Order(null,3),<br /> };<br /> <br /> var k = from p in </order></order></span></span><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left; font-family:'Segoe UI', Verdana, Arial;font-size:13px;" >orderList</span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left; font-family:'Segoe UI', Verdana, Arial;font-size:13px;" > orderby p.ID ?? p.Count<br /> select p; <br />}<br /><br /><br />class Order<br />{<br /> public int? ID{get;set;}<br /> public int? Count{get;set;}<br /><br /><br /> public Order(int? id,int? count)<br /> {<br /> ID =id;<br /> Count =count;<br /> }<br />}<span style="font-weight: bold;"><br /></span></span></span>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-47583932383151202382011-05-15T08:42:00.000-07:002011-05-15T08:46:16.257-07:00A simple example to say the difference between Descendants vs ElementsHere is the XML<br /><br /> <!--?xml version="1.0" encoding="utf-8" ?--><br /> <titles><br /> <book title="Love Story" author="Erich Segal" year="1999"><br /> <book title="Code Complete" author="Steve McConnel" year="2004"><br /> <book title="Rework" author="Jaso Fried" year="2010"><br /> <book title="Delivering Happiness" author="Tony Hseigh" year="2011"><br /> </book></book></book></book></titles><br /><br />if use <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xcontainer.descendants.aspx">Descendants </a><br /><br />XDocument xDoc = XDocument.Load(@"C:\Users\anishmarokey\Desktop\XMLFile1.xml");<br /> <br /> var result = from book in xDoc.Descendants("Book")<br /> select new<br /> {<br /> Title = book.Attribute("Title"),<br /> Author = book.Attribute("Author")<br /> };<br /><br />if use <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xcontainer.elements.aspx">Elements</a><br /><br />XDocument xDoc = XDocument.Load(@"C:\Users\anishmarokey\Desktop\XMLFile1.xml");<br /> <br /> var result = from book in xDoc.<span style="font-weight: bold;">Elements("Titles").Elements("Book") </span><br /> select new<br /> {<br /> Title = book.Attribute("Title"),<br /> Author = book.Attribute("Author")<br /> };Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-35249357747544923592011-05-15T08:22:00.000-07:002011-05-15T08:33:16.886-07:00Sort a class EmployeeHere is a simple example for sorting an Employee class<br /><br /> public class MainClassToSortEmployee<br /> {<br /> public enum SortDirection { Ascending, Decending }<br /><br /> public static List<employee> Sort1<t>(ref List<employee> list,<br /> Func<employee, t=""> sorter, SortDirection direction)<br /> {<br /> if (direction == SortDirection.Ascending)<br /> return list = list.OrderBy(sorter).ToList();<br /> else<br /> return list = list.OrderByDescending(sorter).ToList();<br /> }<br /><br /> static void Main()<br /> {<br /><br /> }<br /> }<br /><br /> public class Employee<br /> {<br /> public string FirstName { get; set; }<br /> public string LastName { get; set; }<br /> public DateTime dateTime { get; set; }<br /><br /> public Employee(string p, string p_2, DateTime dateTime)<br /> {<br /> this.FirstName = p;<br /> this.LastName = p_2;<br /> this.dateTime = dateTime;<br /> }<br /> }<br /><br />next task is to convert it to a Generic Linq<br /></employee,></employee></t></employee>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-72344852373842683872011-05-11T10:22:00.000-07:002011-05-11T10:23:20.831-07:00Can we write Linq in .Net 2.0 ?<span style="font-weight: bold;">yes</span>.<br /><br />To Know more <a href="http://www.albahari.com/nutshell/linqbridge.aspx">Read this</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-58182011408592562842011-05-11T10:05:00.000-07:002011-05-11T10:08:43.617-07:00Concat vs Union in C#List<int> list1 = new List<int>(){1,2,3};<br />List<int> list2 = new List<int>(){1,2,4};<br /><br />var dummyConcat = list1.Concat(list2); // combine all values without distinct<br />var dummyUnion = list1.Union(list2);// combine all values with distinct<br /><br />result for <span style="font-weight: bold;">dummyConcat </span><br /><br /><br /><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALYAAACHCAIAAAA0tDRbAAAEg0lEQVR4nO2dPXLqMBRG2cLbCytgK7T0bxVUzLCIR03jV1KxAGYYJk1q19R6hW2sP/uT8gjJ5J4zt0gcR5bkoyv/aGDhAGZZOOd+/f5LEGmgCCECRQgRKEKIQBFCxM9S5NA655rD7JZvHed965y773evPvTqdHfOuesl/dPHFekLdc4593Y6dycj2PL6Ln6GInG7Jo7S/2n3/pZr9eY6biw/+up0j/zwymk32Tr4lXlG76VF/VcW6Xqz74In1vVLFNm9vw2nJ2iXUqQJtOhKuDT9D35WuDSiJud964/jsozyzG4/71vn2vdVlSKdxVM1EIoEeeW+33n7Dzv7Q9a5dt//2vdLMoYujXPuelmd7s61G7/8rmHJEX1FpkbkuH04PWm7vDIvjcuW053Rvp6bg194YN5Y24yjXgd2+SmX+T3148pEbZzrXj//BQ2Ppex2ySviZ8usJdNdOXqQCpFsGc/l2+n86Cmvur0Z/Q/p6QkP1By8/h22ZEob+yjulLRdfp3TwTB0VDgXPPokFmJsxVzCC/szO9EEtfqdaeNM926ukxWOUt2UIv7JeFQydr8ki3xYEV/QwfSHK944y0r52HPYkinteYpk/musXnIaahTpj1LQt9GQdkoRX8Gx5BpFiuJTFcklvUCRcRzUZZHpZDk90Uwpsjrdm2BO6f+rz/DhoKqbaPzGlimStnFOkX6f8Prj0NZNNCV+jBqmdzSZZgTJaV6ReFikWWRiahsI7cmUlp6h8YKprBWP2d3bP6mY/181l6v5y4VkuI+V2SRtLEzSQ60+dLlKvDJmUt0r4jNueolnx896dEYYCRQhRKAIISJW5A/AQF4RBzCAIiBAERCgCAhQBATFity2y8Vye3tl3eBbUKDIbbtcdKCIRcgiIEAREKAICFAEBCgCAhQBQdVNb8f6+PpqwtfB01UQoAgIUAQEKAICFiaCgCwCAhQBAYqAAEVAgCIg0IoEz995S2MPqchtu3y8lLltl7yiMUfdRMPrXoPUKXJck0XMUaEI04xNihU5rrlYtUmRIuQPy2hFSB/GkYoc14sIfLEFT1dBgCIgQBEQoAgIWJgIArIICFAEBCgCAhQBAYqAgIWJICh5jcfCRNOwMBEEVYqQRSxSqMhwQUIKsQcTDQgqb3pZAm+PglVnXtpgkaJBytau8lzEMDxdBQGKgABFQIAiIGBhIgjIIiBAERCgCAhQBAQoAoJiRXjJa5UCRfgqZ9uQRUCAIiBAERCgCAhQBAQoAoKqm16+ytkiPF0FAYqAAEVAgCIgYGEiCMgiIEAREKAICFAEBCgCAq0In5hoHKkIX+VsnbqJhte9BqlThM+xMkiFIkwzNilWhI85s0qRIuQPy2hFSB/GkYrwVc7W4ekqCFAEBCgCAhQBAQsTQUAWAQGKgABFQIAiIEAREFQoclzzsQAWKVVkWMGKIuYoXgyw3N5u2yWK2KNAkeO6f7mLIiZRivirVVHEJEKR+EOsWDBij5qbXrKISVAEBCgCAp6uggBFQIAiIEAREOQVIYgoUIQQ0SnyD/YnnnjQX4ouAAAAAElFTkSuQmCC" alt="" /><br /><br />result for <span style="font-weight: bold;">dummyUnion</span><br /><br /><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALEAAABfCAIAAAAoBbFgAAAD1UlEQVR4nO2dP47iMBSHucLcJSfgKrT0nCIVEofY1DTZkooDIKGIhjo1tbeIk9g/O04YsTAjf59eMZMF59n+8vLP2ll97f4ShBurj2dA/LTACUIDJwgNnCA0fr8TVWuMqavklh8d50NrjHkc9u/e9fr0MMaY60W2P+eEbcUYY8ztdO5G39vy/jF9hRPar4m92H/a32+xXm+v48ble1+fHqEQtimZrSEHN5lXjJ409XSd6IbP9vmFyX3Eif391s+H1685J2rPg66FS21/cI/7Sz2TyfnQ6tyPggZHcGIivxvnQ2tMe1+nnegkndrljBNe5Xgc9s7n+w+7B6Ux7cH+aufGOdra7c4Oq7le1qeHMe3Wbb/rSbBH14mgNa+P7riH/XLavNQm2k43/TbPbeU27qk2ZhuR0htAWzaq+22iTtSVJiN9TA2vW+G8jnuFSp1wC2BUi+mxGyc+NCDYMk7e7XQehsbJz6pgfwjnw99RXfUdvl6GLZHWxkHRch32y805tL8fKE+1cUzUgLEXqZJWtd7kxZ3wDsWwj4nh3V4nE3azWkXzdmZB7V5SJ77thGtk7/Igx3hgxS0cPtlvibT2Oici3xrTC8Z9kRNd1QlHIOVE2MfE8LrH8NiXpBOL4r86Ebvg8pwYTX+uTmgsOXdMObE+PWrvNGG/ZYu2fxQ9e+7w3HquTrh7nHBi58g35DMUp+85MX/fEcnbKz9pJ1T8sE5MnK16fF0irYVDP170LOvFcIZ2Ph8k5n7r2WvMeSecZLZBHxeWYa84zV5jEu+MRDF7R7zkXpR4dfzyZ1ZEDoEThAZOEBqrr93fPwA91gkD0IMToOAEKDgBCk6AMu1EUxaromzenhF8mpgTTVmsOnAiR6gToOAEKDgBCk6AghOg4AQo6XvRjs3xQ8nBR+A5Jig4AQpOgIIToLD2DhTqBCg4AQpOgIIToOAEKBEnvEfbvPHIj9CJpiyGFxxNWfC6Iztmzh28HM2QGSeOG+pEdqSc4MyRJ9NOHDdcYeZJ3AkqRM5EnKBAZE7oxHGzEhAkL3iOCQpOgIIToOAEKKy9A4U6AQpOgIIToOAEKDgBCmvvQIm+A2PtXdaw9g6UtBPUiRyZcqK/qKBI5AfnDlDm7kVZuJ0fsXVWTmFgHV6GTKzH5PlExvAcExScAAUnQMEJUFh7Bwp1AhScAAUnQMEJUHAClJQTxw1/0CVHJp3oF1DgRHZM/z81Rdk0ZYET+RFz4rixr0NxIksCJ9xFNDiRJeqE/s1AFlHkR/JelDqRJTgBCk6AwnNMUHACFJwABSdAsU4QhBv/AL1BYrOqAxneAAAAAElFTkSuQmCC" alt="" /><br /><br /><br /></int></int></int></int>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-34302468443704460082011-05-11T08:03:00.000-07:002011-05-11T08:05:46.402-07:00Convert IEnumerable to DataTableHere is small example to convert IEnumerable to DataTable by using the keyword <a href="http://msdn.microsoft.com/en-us/library/bb396189.aspx">CopyToDataTable()</a><br /><br />DataTable dt = new DataTable();<br /><br />//Adding Columns and names<br />dt.Columns.Add("ID" ,typeof(int));<br />dt.Columns.Add("Name",typeof(string));<br />dt.Columns.Add("Rank",typeof(string));<br /><br />//Adding Rows and values<br /><br />dt.Rows.Add(1,"anish","First");<br />dt.Rows.Add(2,"marokey","First");<br />dt.Rows.Add(2,"varghese","Second");<br /><br />//querying the result where ID is 2<br />IEnumerable<datarow> result = from p in dt.AsEnumerable()<br /> where p.Field<int>("ID") == 2<br /> select p;<br /><br /> // By using the keyword CopyToDataTable(.net 3.5 SP1 and above) converting the IEnumerable to DataTable<br /> DataTable dtConvertedFromLinq = result.CopyToDataTable<datarow>();<br /></datarow></int></datarow>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-23303998967401907432011-05-11T07:55:00.000-07:002011-05-11T07:57:41.609-07:00Why Field is required for DataTable LinqHere is one good blog for the same<a href="http://blogs.msdn.com/b/adonet/archive/2007/01/26/querying-datasets-introduction-to-linq-to-dataset.aspx"> Click here</a><br /><br />E.g<br /><br />DataTable dt = new DataTable();<br /><br />//Adding Columns and names<br />dt.Columns.Add("ID" ,typeof(int));<br />dt.Columns.Add("Name",typeof(string));<br /><br />//Adding Rows and values<br /><br />dt.Rows.Add(1,"anish");<br />dt.Rows.Add(2,"marokey");<br />dt.Rows.Add(2,"varghese");<br /><br />//querying the result where ID is 2<br />var result = from p in dt.AsEnumerable()<br /> where p.Field<int>("ID") == 2<br /> select p.Field<string>("Name");<br /><br /></string></int>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-48123100868326917612011-05-11T07:47:00.000-07:002011-05-11T07:48:27.714-07:00Add Columns and Name to DataTableHere is a simple example to add values to DataTable<br /><br />DataTable dt = new DataTable();<br /><br />//Adding Columns and names<br />dt.Columns.Add("ID" ,typeof(int));<br />dt.Columns.Add("Name",typeof(string));<br /><br />//Adding Rows and values<br /><br />dt.Rows.Add(1,"anish");<br />dt.Rows.Add(2,"marokey");Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-52249643284466857602011-05-11T02:26:00.000-07:002011-05-11T02:27:24.392-07:00Some good APIs for PDF converter in .NetHere is the some good APIs for PDF Converter<br /><br /><a href="http://www.aspose.com/categories/.net-components/aspose.pdf-for-.net/default.aspx">http://www.aspose.com/categories/.net-components/aspose.pdf-for-.net/default.aspx</a><br /><br /><a href="http://sourceforge.net/projects/itextsharp/">http://sourceforge.net/projects/itextsharp/</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-8104125920974884502011-05-10T11:59:00.000-07:002011-05-10T12:05:27.395-07:00what is the use of parms keyword in C#here is the msdn link for <a href="http://msdn.microsoft.com/en-us/library/w5zay9db%28v=vs.71%29.aspx"><span style="display: block;" id="formatbar_Buttons"><span class=" down" style="display: block;" id="formatbar_CreateLink" title="Link" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmouseup="" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);"><img src="img/blank.gif" alt="Link" class="gl_link" border="0" /></span></span>params</a><br /><br />E.g:<br /><br /><span style="font-weight: bold;">with params</span><br /><br />void Main()<br />{<br /> Method(1,2,3); // you can call it like this<br />}<br /><br /> static void Method(params int[] array)<br /> {<br /> for(int i=0;i < array.Length;i++)<br /> {<br /> Console.WriteLine(array[i]);<br /> }<br /> }<br /><br /><br /><span style="font-weight: bold;">without params</span><br /><br />void Main()<br />{<br /> <br /> Method(1,2,3); // throws error<br />}<br /><br /> static void Method (int[] array)<br /> {<br /> for(int i=0;i < array.Length;i++)<br /> {<br /> Console.WriteLine(array[i]);<br /> }<br /> }<br /><br />you have to do<br /><br />void Main()<br />{<br /> int[] i = {1,2,3};<br /> Method(i);<br />}<br /><br /> static void Method (int[] array)<br /> {<br /> for(int i=0;i < array.Length;i++)<br /> {<br /> Console.WriteLine(array[i]);<br /> }<br /> }Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-20757625846112364772011-05-10T11:26:00.000-07:002011-05-10T12:11:16.104-07:00why the entry point of C# should be static void Main()here is a couple of links which says the answer properly<br /><br />Msdn: <a href="http://msdn.microsoft.com/en-us/library/acy3edy3.aspx">http://msdn.microsoft.com/en-us/library/acy3edy3.aspx</a><br />SO:<a href="http://stackoverflow.com/questions/5954439/c-entry-point-function">http://stackoverflow.com/questions/5954439/c-entry-point-function</a><br /><br />why the method name should be Main()<br /><br />The using System; directive references a namespace called System that is provided by the Common<br />Language Infrastructure (CLI) class library. This namespace contains the Console class referred to in<br />the Main method.<br /><br />taken from <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf">ecma-international</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-56720590465222829892011-05-10T09:22:00.000-07:002011-05-10T09:25:10.565-07:00Dynamic keyword in C#if you want to set the variable at runtime go with <a href="http://msdn.microsoft.com/en-us/library/dd264741.aspx">dynamic</a><br />if you want to set the variable at compile time go with <a href="http://msdn.microsoft.com/en-us/library/bb397696.aspx">var</a><br /><br />e.g in dynamic<br /><br />void Main()<br />{<br /> var k = exampleMethod("23");<br /> Console.WriteLine(k);<br />}<br /><br /> public static dynamic exampleMethod(dynamic d)<br /> {<br /> dynamic local ="string";<br /> int i =3;<br /> if(d is string )<br /> return local;<br /> else<br /> return i;<br /> }Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-79632727640434643792011-05-10T08:03:00.000-07:002011-05-10T08:09:20.857-07:00Tuple in C#in .net 4.0 Tuple keyword is introduced, this is new to C# and old to sql, F# etc,<br /><br />Mostly tuple is used to return multiple values with out using ref or out key word.<br /><br />Public <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; text-align: left; ">Tuple<string,int,textbox></string,int,textbox></span></span> ReturnMultipleObjects()<br />{<br /><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; text-align: left; "> Tuple<string,int,textbox></string,int,textbox></span></span> multipleObjects = Tuple.Create("string",1, new TextBox());<br /> return multipleObjects ;<br />}<br /><br />Msdn Link: http://msdn.microsoft.com/en-us/library/system.tuple.aspx<br />So Question: <a href="http://stackoverflow.com/questions/5951808/c-defined-arrays">http://stackoverflow.com/questions/5951808/c-defined-arrays</a><br />Code Project: http://www.codeproject.com/KB/cs/C_Sharp_4_Tuples.aspxAnishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-45499336498515269502011-05-10T01:25:00.000-07:002011-05-10T01:26:50.293-07:00Hello World in Android using MONOHere is a good article which helps to write a Hello World using MONO<br /><br /><a href="http://mono-android.net/Tutorials/Hello_World">http://mono-android.net/Tutorials/Hello_World</a>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-14209202911132411582011-05-09T09:45:00.000-07:002011-05-09T09:57:37.867-07:00Event Based Async Pattern(EAP)The event-based asynchronous pattern (EAP) provides a simple means by which classes can offer multithreading capability without consumers needing to explicitly start or manage threads.<br /><br />E.g: <a href="http://msdn.microsoft.com/en-us/library/h339syd0.aspx">BackgroundThread</a>, <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.80%29.aspx">WebClient </a>in System.NetAnishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0tag:blogger.com,1999:blog-6433217646226359084.post-74409979586482929042011-05-09T09:27:00.000-07:002011-05-09T09:34:35.826-07:00yield vs return in C#<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left;font-family:'Segoe UI',Verdana,Arial;font-size:13px;" >The<span class="Apple-converted-space"> </span><a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"><span><span class="input">yield</span></span><span class="Apple-converted-space"> </span></a>keyword signals to the compiler that the method in which it appears is an iterator block.<br /><br /></span></span><ul><li>yield can be used to return partially.</li><li>yield maintains the state of the object<br /></li></ul><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left;font-family:'Segoe UI',Verdana,Arial;font-size:13px;" >Simple example<br /><br />void Main()<br />{<br /> foreach(int i in GetDivideByTwo())<br /> {<br /> Console.WriteLine(i);<br /> }<br />}<br /><br /><br /> static System.Collections.Generic.IEnumerable<int> GetDivideByTwo()<br /> {<br /> for (int i = 0; i < 100; i++)<br /> yield return i/2;<br /> }<br /><br /><br />Here is couple of good links<br /><br /></int></span></span><a href="http://stackoverflow.com/questions/410026/c-proper-use-of-yield-return">http://stackoverflow.com/questions/410026/c-proper-use-of-yield-return</a><br /><br /><a href="http://stackoverflow.com/questions/1088442/what-is-the-purpose-advantage-of-using-yield-return-iterators-in-c/1088452#1088452">http://stackoverflow.com/questions/1088442/what-is-the-purpose-advantage-of-using-yield-return-iterators-in-c/1088452#1088452</a><br /><br /><a href="http://stackoverflow.com/questions/3969963/when-not-to-use-yield-return/3970171#3970171">http://stackoverflow.com/questions/3969963/when-not-to-use-yield-return/3970171#3970171</a><br /><br /><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-family:'Times New Roman';font-size:medium;" ><span class="Apple-style-span" style=" text-align: left; font-family:'Segoe UI', Verdana, Arial;font-size:13px;" ><br /><br /></span></span>Anishhttp://www.blogger.com/profile/10249890128081186218noreply@blogger.com0