CSharpFeeds - All your C# feeds in one place.

Sponsors

Feed: Bill Wagner: C# Development Blog | MySmartChannels

Site: http://www.srtsolutions.com/public/blog/20574 Link: http://www.srtsolutions.com/public/rss/20574

Tuesday, January 22, 2008

Looking Inside C# Closures

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 1/22/2008 5:01:03 PM

If you're like me, you understand new language features better when you see what the new language features generate for you. Closures in C# are no different. There's quite a bit that goes on under the covers in a C# closure. Looking at all the code that the C# 3.0 compiler generates can really help you understand what's happening. A little help from Reflector and we can learn a lot. I started with this rather simple C# 3.0 program: class Program{ static void Main(string[] args) ...

[ read more ]

Thursday, January 17, 2008

DNR TV on Learning C#

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 1/17/2008 2:04:00 AM

Carl Franklin and I got together and did an intro to C# for VB.NET developers last month.  The first version is up here:  http://www.dnrtv.com/  Or, watch the silverlight version here:  http://perseus.franklins.net/dnrtv/0096/silverlight/video.html  This discussion is somewhat introductory, it should be approachable for a beginning C# developer. Carl is a great interviewer. Those who know me know that I'm not particularly fluent in VB.NET. Carl does a great job of l ...

[ read more ]

Monday, January 07, 2008

Yet another use for Extension methods : Extending IComparable

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 1/7/2008 2:19:00 PM

I keep finding more uses for extension methods. This time it's extending IComparable<T>. The API signature for IComparable<T> has been around since the dawn of C: if the left is less than the right, return something less than 0, if left is greater than right, return something greater than 0, and if they are equivalent, return 0. Well, its readability leaves a bit to be desired. So I wrote this set of extension methods for any type T that implements IComparable<T>: public ...

[ read more ]

Tuesday, November 20, 2007

Creating Dynamic Queries in LINQ

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 11/20/2007 7:32:10 PM

Toward the bottom of the LINQ to SQL samples is a set called "advanced". I'm not sure I like that title, because "Advanced" really should read "Things you just haven't done yet". The first set of samples gives you a glimpse into the deeper goo inside the Linq to SQL libraries. And, understand that none of this is hidden from you. Come to my CodeMash talk on IQueryProvider and you'll see that you can build the same type of capability into your own data ...

[ read more ]

Monday, November 19, 2007

DataContext methods in LINQ to Sql

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 11/19/2007 12:44:33 AM

Toward the bottom of the LINQ to SQL samples, you'll find several methods discussing the DataContext class. This is an important class that provides the interface between your code and the physical database storage. There are also some convenient methods that can make it easier for you to initialize a LINQ-enabled application for the first time. One of the startup tasks would be to check for a database's existence, and create that database if necessary. This snippet of code shows you ho ...

[ read more ]

Tuesday, October 30, 2007

Linq to Sql and Stored Procedures

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 10/30/2007 1:53:29 AM

Yesterday I discussed Linq to SQL and interoperability with existing database technology. Today I'll look at how Linq to SQL handles stored procedures. Much of the work is done by the database designer, which creates methods that invoke your stored procedures. At its core, all calls into stored procedures call DataContext.ExecuteMethodCall(). ExecuteMethodCall returns an IExecuteResult object. IExecuteResult provides a Result parameter to access the result object. Attributes on each method ...

[ read more ]

Sunday, October 28, 2007

Catching up on LINQ content: Interop with existing database access code

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 10/28/2007 11:37:56 PM

Holy crud. The launch is approaching, and I haven't reviewed the features and samples in the 101 * 4 demos in the SampleQueries application. If I want to have any hope of finishing, I need to do this quite a bit more quickly. Next on the list of 101+ Linq to SQL samples are ones that show that you can use SQL statements in a LINQ query: var products = db.ExecuteQuery<Product>( "SELECT [Product List].ProductID, [Product List].ProductName " + "FROM Products AS [Prod ...

[ read more ]

Friday, October 19, 2007

I hate testing

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 10/19/2007 2:43:20 AM

And that's why I write automated tests. I recently inherited some truly bad code. I'd post some examples, but the codebase is owned by a client, and the code is covered by an NDA. But, to give you an idea how bad it is, here are a few interesting statistics from when I first examined the code: Longest method: 1779 lines (that's not a typo. The same method has a cyclomatic complexity of 204).Number of public fields: 527And, most significantly: Number of unit tests: 0. This project ...

[ read more ]

Monday, August 20, 2007

LINQ to SQL Conversion Operations

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 8/20/2007 8:17:00 PM

Throughout the LINQ to SQL samples, I've been stressing the deferred execution nature of LINQ queries. To refresh, deferred execution means that when you create a LINQ query, the query expression holds an Expression Tree, not the results of the query. The expression tree gets converted to SQL, to be executed at the server. The actual results are only returned when the query is executed. That is the behavior you want most of the time. It minimizes the number of trips to the database. You see ...

[ read more ]

LINQ 2 SQL, Object Identity, and Deferred Loading

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 8/20/2007 2:43:00 AM

Let's continue looking at LINQ 2 SQL and how it handles object identity vs. database identity, and how you can control loading related objects. The object identity concept is pretty straightforward: If you execute the same query more than once, you will receive the same object. Here's a quick example: Customer cust1 = db.Customers.First(c => c.CustomerID == "BONAP");Customer cust2 = db.Customers.First(c => c.CustomerID == "BONAP");Console.WriteLine("cust1 ...

[ read more ]

Sunday, August 12, 2007

LINQ 2 SQL String functions

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 8/12/2007 1:25:00 PM

Yes, it's time to do more LINQ investigation. Beta 2 is out, and now all the sample query applications are delivered as part of the normal install. The samples are all located in C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033 in the standard install. You can (and should) move the zip files under your project directory and from there you can build and run them. One important caveat: You need to run the LINQ 2 SQL samples as Administrator due to the way the samples access the SQL ...

[ read more ]

Monday, July 09, 2007

Reader question about floating point

by wwagner via Bill Wagner: C# Development Blog | MySmartChannels on 7/9/2007 7:00:58 PM

where 2 + 2 = 5, for large values of 2I had a question last week about floating point accuracy.  A customer was having some issues with a sampling algorithm that was supposed to grab timings every 0.0125 seconds. As he sampled data, he returned the elapsed time with every sample.  The timing values in the returned structure weren't what he expected.  He was being bitten by the rounding that takes place in all floating point math.  Inside his code, he was adding 0.0125 to ...

[ read more ]

Reader question about floating point

by via Bill Wagner: C# Development Blog | MySmartChannels on 7/9/2007 3:00:58 PM

where 2 + 2 = 5, for large values of 2I had a question last week about floating point accuracy.  A customer was having some issues with a sampling algorithm that was supposed to grab timings every 0.0125 seconds. As he sampled data, he returned the elapsed time with every sample.  The timing values in the returned structure weren't what he expected.  He was being bitten by the rounding that takes place in all floating point math.  Inside his code, he was adding 0.0125 to a ru ...

[ read more ]

Wednesday, May 23, 2007

Discussion on Constructor Chaining / Accumulative Construction

by via Bill Wagner: C# Development Blog | MySmartChannels on 5/23/2007 7:00:13 PM

Peter Ritchie posted an alternative strategyPeter Ritchie wrote a post here on chaining constructors.His recommendation is: Polymorphic constructors should be called from most specific to least specific.He makes some good points about that, but I do disagree. I agree with the idea of using accumulative construction, or, as I called it, constructor chaining. That's the subject of Item 14 in Effective C#. All my examples in that item took the opposite approach to Peter: I chained the constructors ...

[ read more ]

Friday, April 27, 2007

Orcas Beta 1: Initial impressions

by via Bill Wagner: C# Development Blog | MySmartChannels on 4/27/2007 12:55:12 AM

Hey, it's only been a few daysI downloaded the installabe ISO image for the Orcas Beta 1. (I'm a bit of a control freak when it comes to developer tools, and I want to know what options are going on my machine).I'm running Orcas in a VPC at the moment. I hope to let it out of the sandbox in a bit, but I need more experience with it before I'm ready for that. The first bit of good news is that Orcas Beta 1 runs in Vista (I've got a Vista VPC image running in VPC 2007).  That experience went ...

[ read more ]

Wednesday, April 25, 2007

On Languages and Computer Science Programs

by via Bill Wagner: C# Development Blog | MySmartChannels on 4/25/2007 9:21:18 PM

Just echoing a Scott Hanselman postIt's probably the case that my readership is a proper subset of Scott's, but for those few folks that haven't seen it, Scott wrote an interesting post about languages (human and programming) late last week: http://www.hanselman.com/blog/TheProgrammingLanguageExplosion.aspxFor my part, I've spent most of my professional career between curly braces: C, C++, Java, and now C#. But, in college and in other study on my own, I've used a number of languages from other ...

[ read more ]

Wednesday, April 04, 2007

Productivity enhancements from C# 3.0

by via Bill Wagner: C# Development Blog | MySmartChannels on 4/4/2007 3:05:10 PM

Luke Hoban has a great example of why language enhancements matterYesterday I discussed auto implemented properties. My focus was that the C# langugae team does a great job to see common idioms and extend the language in ways that make us more productve.Luke Hoban made a great point about comparing the querying syntax in C# 2.0 and 3.0.  Notice the difference in length, and readability.  In my opinion, the 3.0 syntax is much more concise, and much more readable.  That's two big pl ...

[ read more ]

A final end to the public fields vs. property debate.

by via Bill Wagner: C# Development Blog | MySmartChannels on 4/4/2007 1:57:31 AM

New C# 3.0 feature offers hope (at least for me)My position on fields vs. Properties is pretty well known (See Item 1 in Effective C#).  However, another group of developers that prefer fields, unless the getter or setter actually do real work.  They feel that always using properties violates YAGNI (You ain't gonna need it).  I suppose there is some truth in that. But my opinion has always been that the cost of binary compatibility is much greater than the cost of just making prop ...

[ read more ]

Wednesday, March 21, 2007

User Interface Smackdown 2007

by via Bill Wagner: C# Development Blog | MySmartChannels on 3/21/2007 1:20:54 AM

Explore Google's GWT, Adobe's Flex, and Microsoft's WPF for creating user interfacesI'm a bit late to this, since Dianne got the ball rolling while I was in Redmond last week.  But there is still lots of time:Registration is now open for the User Interface Smackdown 2007, being held April 4, 2007 at the Ann Arbor ITZone (Spark Central). The user interface toolkits that we will discuss and work with include (at least) Google’s GWT, Adobe’s Flex, and Microsoft’s WPF.I’ ...

[ read more ]

Tuesday, February 27, 2007

More LINQ 2 SQL (finally)

by via Bill Wagner: C# Development Blog | MySmartChannels on 2/27/2007 3:30:18 AM

Where I discuss object identity and nullable queriesIt’s been quite a while since I’ve tackled the DLINQ (sorry, LINQ to SQL) samples on this blog.  The combination of CoedeMash, writing for MSDN, and researching a book has meant that I haven’t done much here in the blog.  It’s time to change that.The next LINQ to SQL sample group is quite simple. They show how LINQ to SQL uses entity references and link tables when resolving relationships between records in dif ...

[ read more ]

Sunday, January 21, 2007

Channel 9: Microsoft Language designers on the future of computer languages

by via Bill Wagner: C# Development Blog | MySmartChannels on 1/21/2007 4:25:06 PM

Anders Hejlsberg, Herb Sutter, Erik Meijer, Brian BeckmanThis is a a great video, and worth watching or hearing more than once.These four gentlemen represent the C#, C++, C#/VB.NET and VB.NET teams.  But, don't pigeonhole any of them as being tied to any one language. They are incredibly smart, and have experience in many different environments. Watch, and you'll learn more about your language, other languages, and why different tools are meant for different tasks.  (You'll also l ...

[ read more ]

Wednesday, January 17, 2007

Changes in the C# Developer Center

by via Bill Wagner: C# Development Blog | MySmartChannels on 1/17/2007 5:49:52 PM

Mark Michaelis and I are sharing spaceMark Michaelis and I are going to be alternating space on the front page of the C# Developer Center.  His first post is on the changes to the Exception handling mechanism for C# 2.0.  My first article takes you on a tour of custom iterators.  I'll be writing a short tip in February, and Mark comes back in March.We're still sorting out several details with Charlie Calvert, Community Program Manager for the C# Group. What I do know is that I'm h ...

[ read more ]

Monday, December 04, 2006

LINQ to SQL

by via Bill Wagner: C# Development Blog | MySmartChannels on 12/4/2006 12:50:59 PM

Optimistic Concurrency: How LINQ to SQL behavesWell, it’s been quite a while since I examined LINQ to SQL.  This installment will show you what LINQ to SQL does when you have some form of errors in the database.  Those errors could be caused by multiple users making modifications, or by a change that violates one of the database constraints.  The first example shows a path where you read and write the data after another user has modified it:public void DLinq71() {   ...

[ read more ]

Wednesday, November 22, 2006

More on What is a Collection?

by via Bill Wagner: C# Development Blog | MySmartChannels on 11/22/2006 8:39:04 PM

Can the compiler protect you from yourself?One of my readers commented recently on his concerns about Object and Collection Initializers in C#.  He raised some concerns about possible confusion over creating the wrong objects based on incorrectly calling an Add function.  The reality is that this is a very low-probability occurrence, and relies on you making some very bad decisions.  Let’s suppose you have an immutable class that supports an Add method to create a new instan ...

[ read more ]

Monday, November 20, 2006

XML Serialization and generic interfaces

by via Bill Wagner: C# Development Blog | MySmartChannels on 11/20/2006 1:00:07 PM

Why, oh why, doesn't that work?I love generics. I like the performance. I like the fact that my more general algorithms are now type-safe. I like the fact that my code is clearer, because the type parameter documents my intended use.But, there’s one thing I hate about generics. I hate that generics don’t play well with the XML Serializer (or the SOAP Serializer). This simple example shows my concerns. Suppose I have this simple type:public struct TimeSeriesPoint{ private readonly Dat ...

[ read more ]

Friday, October 27, 2006

On inferring collections

by via Bill Wagner: C# Development Blog | MySmartChannels on 10/27/2006 3:56:25 PM

Will duck typing work for collections?Mads wrote this blog post about one of the more controversial changes in C# 3.0. Namely, how the compiler determines if collection initializers are appropriate for the requested type.As a quick aside, a collection initializer is a sequence of object initializers that are used to add items to a collection. A trivial example is this:List<string> foo = new List<string> { “hello”, “goodbye”, “That’s all”};Th ...

[ read more ]

Saturday, October 14, 2006

Paging output with Linq2SQL

by via Bill Wagner: C# Development Blog | MySmartChannels on 10/14/2006 1:04:14 PM

Combining Take and Skip to paginate outputTake and Skip give you the capability to grab subsets of records based on the records' position in the set. Combining these commands helps you create pages of output (for a web page, etc).  Here's how:Take grabs the first N elements from a query, and returns only those:var q = (        from e in db.Employees        orderby e.HireDate        selec ...

[ read more ]

Sunday, October 01, 2006

A question of performance on Exceptions

by via Bill Wagner: C# Development Blog | MySmartChannels on 10/1/2006 9:08:21 PM

which I deftly don't answerI received the following question in email recently:While working on a problem report related to making sure that all our database updates are enclosed in try...catches.  Within the try we throw exceptions if anything goes wrong.  The catch clause contains all of the cleanup code.  Along the way, a question came to mind.  What kind of overhead is there in throwing an exception or is there any?  Your first book does not address that subject.The ...

[ read more ]

Thursday, September 28, 2006

Linq2SQL: Group By Order By, and why I prefer C# To T-SQL

by via Bill Wagner: C# Development Blog | MySmartChannels on 9/28/2006 9:23:41 PM

It's saner, more compact, and more clearWhen we last left our heroes, we looked at Joins.  It’s been a while since I’ve posted some serious technical content. There’s been a lot going on internally in our company, and I’ve finally gotten the time to put some stuff together.Also, the LINQ to SQL demos, while interesting, are not as instructive once you know the syntax from the core LINQ samples. The key point of LINQ to SQL is the translation from C# (or VB.NET syntax ...

[ read more ]

Friday, September 01, 2006

DLinq queries: Mathematics functions

by via Bill Wagner: C# Development Blog | MySmartChannels on 9/1/2006 2:12:16 PM

Avg, Sum, Min, Max, and T-SQLThis post will cover the Count/Sum/Min/Max/Avg category for DLinq. I’m changing the format because what’s interesting in DLinq isn’t the C# code, it’s how the DLinq library translates the query operators (and your lambda expressions) into SQL.  So, I’m going to concentrate less on the code and its output, and more on what SQL gets generated from your queries.  Unfortunately, I don’t know the exact mechanism LinqToSql uses ...

[ read more ]

Thursday, August 31, 2006

Best Practices for Exception Management

by via Bill Wagner: C# Development Blog | MySmartChannels on 8/31/2006 3:05:55 PM

Addendums to Scott Hanselman's postFellow RD Scott Hanselman wrote his thoughts on Good Exception Management Rules of Thumb here.  I agree with everything he said, and I'll add a few points.  By the way, to get even more about best practices and exceptions, you should read Chapter 7 of Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries, by Cwalina & Abrams.Scott says:If your functions are named well, using verbs (actions) and nouns (stuff to ...

[ read more ]

Friday, August 25, 2006

LinqToSql: Translating C# to SQL

by via Bill Wagner: C# Development Blog | MySmartChannels on 8/25/2006 9:12:16 PM

How the LinqToSql libraries translates query expressions into T-SQLThis blog entry will finish the Where category of DLinq samples. Most of the logic is familiar, if you’ve read my earlier series on the core LINQ language enhancements.  However, there are some interesting twists on the way query language works when you are pulling data from a SQL database. But, you’ll only care if you are trying to round-trip the data, modifying it and storing it back in the database.The first s ...

[ read more ]

Saturday, August 05, 2006

Linq to SQL (the technology previously known as DLinq)

by via Bill Wagner: C# Development Blog | MySmartChannels on 8/5/2006 2:53:22 PM

Where and how does that work?Now that we have finished the core LINQ queries, it's time to begin the LINQ to SQL (previously known as DLINQ) discussions.The first LINQ to SQL sample is pretty simple:public void DLinq1() {    var q =        from c in db.Customers        where c.City == "London"        select c;    ObjectDumper.Write(q);}An abbreviated po ...

[ read more ]

Wednesday, August 02, 2006

C# Feeds launches

by via Bill Wagner: C# Development Blog | MySmartChannels on 8/2/2006 2:06:42 AM

All C# Feeds in one place (I'm already subscribed)Fellow Regional Director, and the guy behind ASPAlliance.com, Steven Smith, has launched C# Feeds, a site that brings together C# feeds, moderated so that you don't get all those 'I'm going on vacation' posts.I'm proud that he felt my little blog here was worthy of inclusion.See AlsoC# Feeds home pageLearn all about it.The C# Feeds feedsubscribe here ...

[ read more ]

Monday, July 31, 2006

Notice on the end of NDoc

by via Bill Wagner: C# Development Blog | MySmartChannels on 7/31/2006 2:40:09 PM

I think this says something about Open source as a business modelKevin Downs, the force behind NDoc is dropping work on Open Source Software.  He sent an email to many of the members of the NDoc project.  It was posted here:http://weblogs.asp.net/bhouse/archive/2006/07/26/NDoc-2.0-_2D00_-R.I.P.aspxFirst, my own confession:  like many others, I used Ndoc and paid diddly.  On the other hand, I fixed a couple of issues, and helped publicize the project in a couple of magazines.I ...

[ read more ]

Wednesday, July 12, 2006

Join Together

by via Bill Wagner: C# Development Blog | MySmartChannels on 7/12/2006 10:36:06 PM

Cross Join, Group Join (the final core LINQ entryBelieve it or not, this is the last entry on the core LINQ samples. (Of course, that still leaves LINQ to SQL and LINQ to XML (the technologies formerly known as DLinq and XLinq).  This entry covers the Join extension method and keywords. ‘join’ does a simple Cross Join between two disparate sequences.  For example, this method builds a list of products and categories based on a list of chosen categories:public void Linq102() ...

[ read more ]

Wednesday, June 21, 2006

Soma on LINQ

by via Bill Wagner: C# Development Blog | MySmartChannels on 6/21/2006 7:50:33 PM

Soma discusses the LINQ components, and the LINQ namesRead all about it here:http://blogs.msdn.com/somasegar/archive/2006/06/21/641795.aspxAnd no, I'm not changing all my previous LINQ blog items to reflect the new names. ...

[ read more ]

Deferred vs. Immediate query

by via Bill Wagner: C# Development Blog | MySmartChannels on 6/21/2006 6:34:04 PM

Do it now, or do it laterToday, I’m going to discuss two important linq concepts: custom sequence operators and deferred vs. immediate execution.First, lets consider the custom sequence operator. This method computes the Dot Product of two vectors:public void Linq98() {                int[] vectorA = { 0, 2, 4, 5, 6 };    int[] vectorB = { 1, 3, 5, 7, 8 };    int dotProduct = vectorA.Combine ...

[ read more ]

Wednesday, June 07, 2006

Miscellaneous LINQ methods

by via Bill Wagner: C# Development Blog | MySmartChannels on 6/7/2006 8:02:16 PM

Concatenation and EqualAllThis next installment is a grab back of miscellaneous methods: Concat, and EqualAll.Concat() is pretty simple, it just builds a sequence that contains all the elements in both collections:int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };int[] numbersB = { 1, 3, 5, 7, 8 };var allNumbers = numbersA.Concat(numbersB);Console.WriteLine("All numbers from both arrays:");    foreach (var n in allNumbers) {        Console.Write ...

[ read more ]

Sunday, June 04, 2006

More LINQ: Aggregation operators

by via Bill Wagner: C# Development Blog | MySmartChannels on 6/4/2006 8:22:05 PM

Sum, Product, Averages and moreDanger, long post comingThe next (large) set of samples are the aggregation samples.  The aggregation samples perform some calculation on the results of a query and return that single result.  For example, this method counts the number of distinct numbers in the array containing the factors of 300:int[] factorsOf300 = { 2, 2, 3, 5, 5 };int uniqueFactors = factorsOf300.Distinct().Count();Remember from earlier that Distinct() removes any duplicates from a s ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us