DCSIMG
c# - IronShay

Browse by Tags

All Tags » c# (RSS)

My Interview on Herding Code is Published!

At this year’s NDC I had the honor to chat with Jon Galloway and Scott Allen, who are half of the Herding Code podcast crew. We chatted about subjects related to my NDC talks – Roslyn, C#’s dynamic capabilities, and the DLR.  Last week our chat was published as an Herding Code episode, and it is available to hear and download at http://herdingcode.com/?p=463 . Enjoy the episode and thanks Herding Code for having me! All the best, Shay.

Sample Code from my “What?!? C# Could Do That?!?” Session

In the last few months I had the honor of presenting my session “What?!? C# Could Do That?!?” at different conferences and user groups around the world. The session is mainly about different things you can do with C#’s dynamic capabilities, IronRuby and also a bit about the upcoming Roslyn “Compiler as a Service” project. I’ve received several requests to upload my sample code. Therefore, I’ve just made it available on my github page - https://github.com/shayfriedman/WhatCSharpCouldDoThat-Sample...
Posted by shayf | with no comments

C# One Liners

I love programming languages. I think they are beautiful. One of the best things about learning different programming languages is finding the different approaches and techniques of each language. This also allows you to incorporate them into other programming languages. One of my favorite languages is Ruby, and Rubyists have this habit of writing meaningful code in one line, AKA “one liner”. C#-ers don’t do one-liners very much, probably because they couldn’t write cool one-liners till not so long...
Posted by shayf | with no comments
תגים:, ,

Slides and Code Samples from my Talk at LIDNUG - What?!? C# Could Do That???

On Thursday I had the honor to do a virtual talk at LIDNUG – the LinkedIn .NET User Group. A stage where lots of .NET celebs like Scott Gu, Jeffery Richter, Jeff Prosise and others have talked in the past. I’d like to thank all the attendees and the LIDNUG crew who made this possible – Inbar, Peter and Brian – you guys rock! About the talk – I focused on the dynamic capabilities of C#. Started with some black magic done using the dynamic keyword, then moved on to practice witchcraft with the combination...

My Leading Candidate for Worst C# Feature – Method Hiding

I love C#, I really do. Of course is has its little annoying quirks here and there, but in general it is, IMHO, one of the best static programming languages out there. Having said that, one thing that makes me wonder “WHAT THE HELL WERE THEY THINKNING?!?$?!?” every single time is the feature known as “ Method Hiding ”. What is Method Hiding? Method hiding, in short, is the crippled, mentally-ill brother of method overriding. For example, look at the next code: class A { public string GetName() {...
Posted by shayf | 1 comment(s)
תגים:,

Please Use TryParse and Avoid Parse+Try/Catch

Recently I’ve run into a piece of class which was operating as the central place for type conversions in the system. While the idea of having such a class doesn’t sound like a problem, the way it’s been implemented definitely is. Most of the conversion methods looked something like that: public int ToInt(string value) { try { return Int32.Parse(value); } catch { return DefaultValue; } } I took this method for a test drive – I executed it within a loop and put a stopwatch before and after. The next...
Posted by shayf | with no comments
תגים:

Forget 42, –1 is My New Answer to Life

I’ve just stumbled upon the next code statement – Thread.Sleep(-1) . It left me wondering what was happening there since MSDN tells you nothing about a –1 value for the milliseconds parameter: “The number of milliseconds for which the thread is blocked. Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute. Specify Infinite to block the thread indefinitely.“ – System.Threading.Thread.Sleep, MSDN To check that out, I opened the IronRuby interactive...
Posted by shayf | with no comments
תגים:,

LINQ Tip: Chain Ordering

Assuming you have the next code: public class Person { public string Name { get; set; } public int Age { get; set; } } public class Whatever { public void Do() { var people = new List<Person> { new Person {Name = "Shay Friedman", Age = 27}, new Person {Name = "Shawn Doe", Age = 51}, new Person {Name = "Elvis Presley", Age = 76} }; } } And now you want to order it first by name and then by age using LINQ. If you were to do that: var orderedPeople = people.OrderBy...
Posted by shayf | with no comments

return a = “hello”; What will Happen?

I came across an interesting piece of code the other day, something I didn’t even know possible in C#. Consider the next code (which doesn’t make lots of sense, but it gets the point across): public string Test() { string a; return a = "hello"; } What do you think will happen? what will be returned from this method? … …… …………. ……………… So? … …… …………. ……………… The answer is that this method will return “hello” . Why did it happen? When thinking more about it, this behavior is expected. It becomes...
Posted by shayf | 1 comment(s)
תגים:,

I’m a Microsoft MVP!

I’ve just received an email from Microsoft saying I’m a new Microsoft MVP!!! The MVP award is officially in Visual C# but it is mainly for my IronRuby activities (there’s no specific IronRuby MVP award yet). I’d like to thank Sela , Guy Burshtein , IronRuby and you for helping me in the process of becoming a Microsoft MVP. I’m very excited and looking forward to MVPing! All the best, Shay. [This post was cross-posted from my main blog: IronShay.com ]
Posted by shayf | 12 comment(s)
תגים:, , ,

Use .NET Built-in Methods to Save Time and Headaches

During our everyday programming tasks we run into several repetitive code blocks that after the 20th time you implement them become really annoying. The worst case is to re-implement these code blocks every time, and the better case is to create a central class library with helper classes and methods. However, a large amount of these tasks can be achieved easily with built-in .NET methods. In this post I will go through several repetitive code blocks and show you how to implement them using built...
Posted by shayf | 4 comment(s)
תגים:, ,

Is String.IsNullOrEmpty Good or Bad?

I started to wonder about that when I was looking for an equivalent method in Ruby. Apparently, Ruby doesn’t come with such a method built-in, but you can add it very easily by using Ruyb’s monkey patching abilities. This is odd, because Ruby is the greatest language and has everything you possibly need (and IronRuby is even better! :) ). So why isn’t there an IsNullOrEmpty-like method? Well, they might just didn’t think it was important enough. And there might be a different answer, maybe the decision...
Posted by shayf | with no comments

C# Recorder using IronRuby

[This post is the second in my series of IronRuby samples. Read the first one here ] The release of Visual Studio 2010 Beta 2 and IronRuby .Net 4.0 Beta 2 CTP has brought some AMAZING abilities to the .Net world like the dynamic keyword. This keyword is a revolutionary little thing. It takes everything you know about C# and throws it away – explicit types, locating syntax errors in compilation time, compiled code… Sounds bad? well, it is just AWESOME!!! The dynamic keyword brings so much goodness...
Posted by shayf | with no comments

Visual Studio Tip: Compilation Symbols

There are times when we need to use different code statements for different build configurations – this means that some code will not exist in assemblies that are built in certain build configurations. Compilation symbols come to help in this case. You can set a symbol that will exist in  a specific build configuration and then use it inside your code files to write or exclude code when this project is built using this build configuration. The most familiar case of this scenario is debug and...
Posted by shayf | with no comments
תגים:, , , , ,