a blog about Development and Tech stuff by Kristian S. Ravndal RSS 2.0
# Wednesday, April 15, 2009

Finally C# gets optional/default parameters!

One of the things I missed most, when moving from PHP to C#, was the way PHP let you pass along default parameters for any function. Now it look like C# 4.0 gets the same feature. Now I often find myself writing lots of overloaded methods, just because I want it to be easier to use the methods later on in the project

So this is how it is done today:
Illustation image

However, with the new feature in C#4.0, you can now put default values directly into the method:
Illustation image

That little line of code, covers all of the methods I wrote with C#3.5. The only thing to note, is that when you use similar input types for the parameters, it always used the first default values it finds. In the next example, using “foo(“s string”, false,10)” will set b = false, since it’s the first of 2 boolean default values.
Illustation image

Wednesday, April 15, 2009 8:34:51 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
C# | Tips&Tricks | Visual Studio
# Saturday, October 25, 2008

Some Visual Studio tweaking tips!

I spend a lot of time in Visual Studio, and most of the default settings are usually ok. But I there is always something you can do to improve your experience with the IDE. This is more of a follow up to the blogpost of Gøran Hansen <a href="http://blog.goeran.no/PermaLink,guid,ab922a6a-702e-4ec8-8437-c643b5e6939c.aspx">”Pimp my Visual Studio 2008 and developer tool belt!“</a> . But this will cover some basic tweaking for people new to Visual Studio.

In this article I’ll cover some basic “tweaks” to Visual Studio:

  1. Colors
  2. Recent Projects
  3. Default Project Location
  4. Text Editor

Colors

When you spend a lot of time looking at the screen, your eyes have to work more when your screen is filled with a lot of light and contrasts. Therefore it’s a good idea to make a few changes to your codeview. So the most relaxing view your eyes could have, is a dark background with a non-contrast colors on your code/comments. There are several predefined colorsets out there, I just got a new favorite today, the one from Gørans blogpost. (Direct link to the colortheme)

Import Settings:

  1. Download and unzip the file.
  2. Open Visual Studio, and open “Tools->Import and Export Settings”
  3. Select “Import selected environment settings”
  4. Save or overwrite your current setting. I’d save em, you might want to revert later on.
  5. “Browse” and locate your unzipped file. ->” Next” and “Finish” and you are done.

Illustation image

Manual color change:

If you want to change your colors yourself, open Visual Studio and open “Tools->Options”, then navigate to “Environment->Font and Colors”

Recent Projects

if(you == me) then you’ll probably have a lot of small projects, which you created just to test out some new things, a library or just showing “how it works” to a colleague. In that case you end of with a bunch of “unimportant” projects in your recent projects list. I think it’s annoying, so here is the fix:

Remove items

  1. Run -> Regedit.exe
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
    • 8.0 = VS 2005
    • 9.0 = VS 2008
  3. Delete the list of items you don’t need, and you are done

Illustation image

Show more items

Even though I just show you how to remove all the unnecessary projects from the list, I still like to see more than just a few projects.
In Visual Studio: Open “Tools -> Options”, navigate to “Environment -> General”. Here you can control how many projects that will show up on your startpage. On My screen, 20 projects fits well.
Illustation image

Default Project storage location

Default location for your projects is “My Documents\Visual Studio 2008\Projects”. To change this open Visual Studio, go to “Tools->Options”, navigate down to “Projects and Solutions”. Here you can browse to your favorite project/code location and make it default. I prefer to have it outside of the “My Documents” folder, since sometimes the code/folder hierarchy gets a bit long. And if you use roaming user profile (like at school or work), you might get some problems. I have all my code on a different disk with automatic backup. Illustation image

Text Editor

The text editor has a few useful settings you can do. Yet again, in Visual Studio, open “Tools->Options”, navigate to “Text Editor”. The options are mostly self explaining. The only thing you should notice that you have an option “All Languages”, which basically alters all the editors, regardless of what programming language you use. I always enable line numbering here.

Saturday, October 25, 2008 10:53:50 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Visual Studio | Tips&Tricks
# Tuesday, July 22, 2008

Often it is very useful to have a console besides the winform/wpf application. And its really easy to :)
Create an available class:

using System;
using System.Runtime.InteropServices;

public static class ConsoleEx
{

/// <summary>
///
Shows the Console
///
</summary>
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();

/// <summary>
///
Hides the Console
///
</summary>
[DllImport("kernel32.dll")]
public static extern Boolean FreeConsole();

}


I then use it like this in my Code (WPF App):
public partial class App : Application
{

public App(){

#if DEBUG
ConsoleEx.AllocConsole();
#endif

}

}

You could use this with a Linq DataContext:

MyDataContext.Log = Console.Out;

Tuesday, July 22, 2008 12:49:06 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Tips&Tricks
# Friday, July 18, 2008

While we were down in Paris on Imagine Cup, we encountered a big problem. Our server was running live in Oslo (Norway), and the internet connection was too slow to actually load the pages we needed. But it did however; work well in remote desktop as it takes lower bandwidth than a whole website with all the images. Imagine Cup had a firewall blocking just about everything about standard web ports (80,433), so we had to change the default port for Remote Desktop.  

In order to change the Remote Desktops default listening port, you actually need to do a little registry hack.

Open regedit, and navigate to

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber

On the Edit menu, click Modify, and select Decimal (unless you prefer the hex values)

Now, restart “Terminal Services”, and it should be up and running on the new port.

We switched the port to 443, and everything worked like a charm. A special thanks to Rune Zakariassen for lending us the 3G connection to fix it all.

Friday, July 18, 2008 12:46:33 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Tips&Tricks
Navigation
Archive
<April 2009>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Other blogs
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Kristian Sølve Ravndal
Sign In
Statistics
Total Posts: 5
This Year: 0
This Month: 0
This Week: 0
Comments: 3
Themes
All Content © 2010, Kristian Sølve Ravndal
DasBlog theme 'Business' created by Christoph De Baene (delarou)