... Home Contact

Krzysztof Koźmic's blog

Designed in Poland, assembled in Australia.


Show appreciation: My Amazon.com Wish List


Me@Twitter

    Currently reading

    Article Categories

    Archives

    Post Categories

    MyPersonal

    Syndication:

    C

    There are 15 entries for the tag C

    I want that in C# 4.0

    I've been playing with Boo recently and I find it to be very powerful language. One little thing I like particularly is, that I can do this: name = "Krzysztof"print "Hello, ${name}, on the beautiful day of ${date.Today}" And get this: Can I please have this in C# 4.0? Technorati Tags: Boo, C# 4.0, String Interpolation

    C# tricks: Array initialization in C# 3.0

    I found pretty slick new feature in C# 3.0 that I haven't seen anyone mentioning before. In C# 2.0 to initialize List<T> inline you had to use arrays, like List<string> keys = new List<string>(new string[]{"key1"}); As you probably already know, in C# 3.0 you can initialize collections in in similar way like you did with arrays in C# 2.0: List<string> keys = new List<string>(){"key1"}; This has been said many times in many places. What I missed however, was that syntax for initializing arrays changed as well. Now you can simply write: string[] keys = new[]{"key1"}; Did you know that? Technorati Tags: C# 3.0, array initialization

    C# tricks: set and return in one line

    I found nice trick. Instead of writing: private string SetNewName() { string newName = GetName(); _name = newName; return newName; } you can write private string SetNewName() { ...

    ReSharper 4.0 EAP... you said what? January?

    January came and went, and much anticipated ReSharper 4.0 Early Access Program is still not available. It seems, that we'll have to wait another two weeks, before I stop turning off ReSharper every time I want to write something using new C# 3.0 features. What bothers me however is that, although I do understand the vastness of the tool, I'm more and leaning towards agreeing with Alan's comment on a recent post. C# is getting bigger, .NET is getting bigger, and it looks like JetBrains starts having troubles to keep up. I hope I'm wrong. Technorati Tags: ReSharper, EAP, C#...

    Hello World: the 'new' keyword

    Everyone knows what the new keyword is for in C# - you use it to call constructor of an object, right? What can be simpler? Actually, that's true, but not the whole truth. That's the most common way to use it. However, new is one of contextual keywords, which means, it can have different meaning, depending on the context where it's being used. The new keyword can be used in three scenarios: the one presented above, everyone immediately thinks of - creating objects. as modifier, to hide members of a base class. as generic constraint. Creating objects is pretty...

    Framework Tips V: Extension Methods and nulls

    You can call extension methods on null elements. It's obvious when you think about it: its a normal static method where you specify its first parameter with this. using System;namespace ExtensionMethods2{ class Program { static void Main(string[] args) { string isNull = null; Console.WriteLine(isNull.IsNullOrEmpty()); string isNotNull =...

    Using 'using'

    Using classes (and structures for that matter) that implement IDisposable has one implication: when you're done using it, you should ASAP call it's Dispose() method. Like in the example: Pies item1 = new Pies("Pies 1"); Console.WriteLine("Accessing {0}", item1.Name); item1.Dispose(); To make life easier, and not have to remember to call this method directly you can alternatively use some 'syntactic sugar' in form of the 'using' keyword, and...

    I'm really loving new C# 3.0 features

    The more I use new C# 3.0 syntax the more I love it. I basically still use .NET 2.0/3.0 and VS 2005 at work, but at home I'm migrating to Orcas. And I have to admit that more and more, when I'm at work I wish I could use new syntax. var keyword: it's as simple as it can be, but when you get used to writing: var filteredItem = filter(item); instead of:FilteredItem<MtfModificationLog> filteredItem = filter(item); it's really hard to go back. Initially I thought that using this new keyword would make code less readable. That I would have to...

    Extension Methods "Hello World" I: Introduction

    I decided that it's about time to familiarize myself with new features of .NET 3.5 and C# 3.0. And I don't mean see an overview, because I've read many times about what's new in it, and I have basic understanding of all those new goodies that new version of framework/language brings. What I mean by familiarize is understand thoroughly and that is what this "Hello World" series (hopefully) is (hopefully) about. I'm gonna start with extension methods as this is what I've started playing with already, and then... well we'll see :) Extension Methods are a completely new concept to OOP world (at least...

    A few words about Extension Methods and Regex builder library

    LINQ is great. It's what everyone has been talking about for some time now, and it's the biggest thing that comes with .NET 3.5. But I guess that those saying that with time, people will appreciate other new things in C# 3.0/VB9.0 were right. I'm not even sure that LINQ will be THE feature I'm gonna use the most. For some time now, in my spare time I've been working on a project that I'm going to publish up on codeplex. I know that I've chosen the wrong order here (first, created site for project, then started talking about it,...

    Fun with ?: operator

    First of all, take a look at the following code: private string _targetText; private int _maxLines; private int _maxSize;   public int Lines { get { if (_targetText ==...

    Compare paths from the end in C#

    Today at work, a colleague came to me with quite interesting problem. He needed to find out first common directory for two given paths starting from the end. For example, for given paths like: c:\documents and settings\some user\my files\projects\project1\initialFiles\somefiles\ and d:\ My Projects\project1\ChangedFiles\MyFiles\ It would return 'project1'. I was surprised to find out that neither System.IO.Path, nor System.IO.Directory allows you to that. Here's simple solution I created for him. public static string FindLastCommonParentFolder(string path1, string path2) { ...

    Updating Controls in Windows Forms

    How often do you find yourself writing code like this: Code Snippet string[] files = GetFiles(path); filesListView.BeginUpdate(); for (int i = 0; i < files.Length; i++) { //possibly something more ...

    Partial Methods - the most useless c# 3.0 feature?

    I feel puzzled. On the one hand, I KNOW that Anders, Wes, and other people working on c# 3.0 language/compiler, are very smart people, yet I fail to see solid arguments why extend c# 3.0 with partial methods. Wes tried twice explain this feature, and I have read both posts twice, just to make sure I didn't lose the gist of it. To quote him: Partial methods are methods that enable lightweight event handling.  Here is an example declaration: partial class C{  static partial void M(int i);} The idea is that you have partial method declaration (notice the...

    How to embed custom control in ToolStrip

    ToolStrip is very useful container control, but it has it's default set of controls you can put onto it. What if you wanted to have, say DateTimePicker, or some totally custom control you have made? You can inherit it from ToolStripItem, override some methods and properties, but there is a much quicker way, if you don't need any custom behaviour. To illustrate this i created simple form with ToolStrip, and I embeded DateTimePicker into it, as you can se below (code follows) As you can see, all the magic that happens is thanks to ToolStripControlHost class. private void...