Arrays and Generic Lists in C# (Part1 )

I have had a request to discuss C# arrays but in general  I don’t use arrays much anymore. I use generic Lists all the time mainly because the list is dynamic and can be resized easily. Arrays in comparrison are a static amount of memory and need to resized to handle additional items. The following is a simple console app (all it does is sort an group of ints, add another int, sort again and then print the list) that demonstrates what I am talking about – no linq yet I’ll add that to part 2 …

using System;
using System.Collections.Generic;

namespace ArraysAndLists
{
    class Program
    {
        static void Main(string[] args)
        {
            //Why I don't really use arrays any more - 
            //we will sort an array add another item and sort again

            int[] numberArray = { 4,1,3, 1, 3, 4, 5 };
            Array.Sort(numberArray);
            int[] numberArray2 = new int[numberArray.Length+1];
            numberArray.CopyTo(numberArray2,0);
            numberArray2[numberArray2.Length - 1] = 2;
            Array.Sort(numberArray2);
            Console.WriteLine("Array Sorted");
            for (int i = 0; i < numberArray2.Length;i++ )
            {
                Console.WriteLine(numberArray2[i]);
            }

            //Why I love generic lists
            //we will sort an array add another item and sort again

            List<int> numberList = new List<int> { 4, 1, 3, 1, 3, 4, 5 };
            numberList.Sort();
            numberList.Add(2);
            numberList.Sort();
            Console.WriteLine("Generic List Sorted");
            numberList.ForEach(i => Console.WriteLine(i));

            Console.ReadLine();
        }
    }
}

I did find a great article on datastructures in C# btw, and in fact its part of a game development series so if you are interested in a more detailed analysis of .NET collection classes (Arrays,Collections,Lists etc…) have a look

http://create.msdn.com/en-US/education/catalog/article/data_structures

Cheers

Dom

 

Change in focus : domscode.com

Not a very interesting post, more a clarrification on the scope of the blog. I originally created the blog as a resource for .NET and iPhone development, but with work and family commitments its hard to extend my iPhone skills at the moment and rather than try and maintain a 50% split – I am now going to cover my major interests of web, mobile and games. For the record,  I am not dropping iPhone development – I just don’t have as much  time as I would like to devote  to XCode/Objective C. Also, Whilst I have only really dappled in games development – its a major interest for me and the vast number of my tutorials are based on games, I think its fair to extend this focus. So what will change – in some ways not a lot, although I expect to extend the focus onto XNA development. Now XNA (Xbox, Windows Phone and Windows game development) is all .NET based anyway so thats not a hug change from present.

Dom

Criticism against the N-Layered App

I blogged a couple of weeks ago about an excellent tutorial on enterprise scale development. In the last couple of days I have come across some significant criticism of this resource and I think its important to highlight this critism (right or wrong) particularly as the two authors are very significent members of the .NET community (Rob Connery and

http://wekeroad.com/post/7102729511/a-simple-example-thats-incredibly-complex

and

http://ayende.com/blog/tags/reviews (scroll down to the first of 10 blogs on the subject of Review: Microsoft N Layer App Sample)

I will make a response in the next day or so

Dom 

 

Enterprise Scale .NET Guidance

You know there are a million .NET sample apps, Tutorials, You Tube Video Tutes, MIX/PDC Videos,Console Apps and Hello Worlds going around for any given aspect of the .NET. They have an important role to fill when you need to get a few lines of sample code to try out or just build a quick CRUD application to demonstrate aspects of a tool(s). Getting quickly into things like MVC, Silverlight,WPF and jQuery for me has been based on these types of resources because its a great starting point into a Technology. It’s also a great way to get the few lines of code you need to get that SPECIAL functionality into your application.

There is however a general lack of resources when looking at the enterprise scale development. This gap is fairly significant because in general without reference points for enterprise scale development it can be hard to start building a large application unless you have existing code or developed those scale applications before. There are a few excellent books and attached sample projects but its rare that these types of artifacts are free. Design patterns and guidance do exist. Martin Fowler, Eric Evans,Uncle Bob Martin and others have developed a stack of guidance,patterns and practices but again its rare that this guidance are combined into a significant sample application.

Don’t dispair. I have found a great resource and guess what? Its Free!!!

http://microsoftnlayerapp.codeplex.com/

In terms of tool kit the following are the key components:

  • WPF
  • Silverlight
  • MVC (I removed the other UI projects just to keep the sample MVC only)
  • Entity Framework
  • Unity
  • Moq

It’s great because its not just a significant sized application. It’s not massive mind you but its infrastructure is significant. It contains cross cutting areas like Security and Logging and shows how to structure an application into a logical set of layers. What is really important though is the quality of the documentation. The massive PDF** is a great document. Its well written and has a very strong explanation of the design principles used that are based heavily on the major design principles we know and love (SOLID, GoF Design Patterns etc…). As it says on the site:

“Its main goal is to show how to use .NET 4.0 wave technologies implementing typical DDD patternsN-Layered Architecture, Domain Entities, Aggregates, Repositories, Unit of Work, Domain Services, Application Services, DTOs, DTO-Adapters, etc

**I have only really reviewed the V1 version and although thats still MVC2 – it still does the job of describing how to build an enterprise scale .NET app.

Happy Coding

Dom