|
James T. Johnson wrote:
To put this another way, C# is already more complex than we'd like it to be,
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
|
I just spoke with Joe Nalewabau (Product Manager for C#) and asked him why default params were not included in the language. I figured you might want to hear the "inside story":
[Joe Nalewabau] - Default parameters were not added due to the versioning issues associated with them. Essentially when you add default parameters the compiler essentially burns the default value in to the callers code when the code is compiled. This means that if you change the default values all clients must be recompiled to take advantage of the new value -
rather than have the class library itself decide what the default values should be.
Hope this helps.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Thank you for information. This is quite reasonable (but sometimes default parameters are very usefull
Tomiga
|
|
|
|
|
I'm with you. I'd rather have the default params. As Christian stated, people are just going to inject work-arounds to the lack of support for default params that are cause the same problems that resulted in their omission to begin with
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Hello All,
I'm having some problems reading values off a remote machine's registy. When I run the following code I get a System.NullReferenceException all the time. Any Ideas why ? Thanks in advance...
-Koby
using System;
using Microsoft.Win32;
namespace RegExlorer
{
class RegExplorer
{
public static void Main()
{
RegistryKey remoteKey;
object myObj;
// try to open HKEY_CURRENT_USER hive on remote machine
remoteKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, "beast4-009");
// try to open (HKEY_CURRENT_USER\)Volatile Enviornment" hive on remote machine
remoteKey.OpenSubKey("Volatile Environment");
// get value
myObj = remoteKey.GetValue("USERDNSDOMAIN");
// print the result out to the screen
Console.WriteLine(myObj.ToString());
// wait for a key stroke
Console.ReadLine();
}
}
}
|
|
|
|
|
There are actually two separate problems here.
1) You're using the RegistryKey from the OpenRemoteBaseKey call to get the value of the subkey when the OpenSubKey returned the RegistryKey you need to use.
2) You need to specify permissions (using the RegistryPermission class) to work with the remote registry.
Here's a quick example I just typed up and ran on my home network. Obviously, you'll need to change your machine name:
using System;
using Microsoft.Win32;
using System.Security.Permissions;
namespace RegExlorer
{
class RegExplorer
{
public static void Main()
{
try
{
RegistryPermission f = new RegistryPermission(
RegistryPermissionAccess.Read,
"\\cosette\\HKEY_CURRENT_USER\\Volatile Environment\\0");
RegistryKey remoteUserHive;
RegistryKey volatileEnvKey;
object myObj;
remoteUserHive = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, "COSETTE");
if (remoteUserHive != null)
{
volatileEnvKey = remoteUserHive.OpenSubKey("Volatile Environment");
if (volatileEnvKey != null)
{
myObj = volatileEnvKey.GetValue("LOGONSERVER");
Console.WriteLine(myObj.ToString());
}
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Further testing seems to indicate that the permissions is not needed and that your only problem was not using the RegistryKey returned from the GetSubKey method. You might want to play around with this, but this code works and should get you pointed in the right direction.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Thanks for the swift reply Tom the code that you have provided me worked.
-Koby
P.S.: I just ordered a copy of your book
|
|
|
|
|
Very cool on both issues
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
I want to convert a colored bitmap to a Grayscaled one...
so we wonder if there is function doing this in C#....
Thanks in advance..
|
|
|
|
|
Yes, I've written a series of articles on image processing in C#, the first one has a greyscale function.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Well, I finally got the C# books that were recommended by CP users (or maybe I should say book). I bought "Inside C#" by Tom Archer, and "C# and the .NET Platform, by Andrew Troelsen. The second book was supposed to Charles Petzold's latest. Could anyone give me a comparison on what they thought between Charles Petzold and Andrew Troelson? I'm not sure if it's worth returning the book and getting the one that I was supposed to.
TIA
Mark Donkers
A witty saying proves nothing.
-- Voltaire
|
|
|
|
|
They are totally different - C# and the .NET platform is a whirlwind tour of C# and .NET, and the Petzold book covers in depth GDI+ and all the aspects of writing client apps in C#. I'd return it, you're going to have heaps of double up with Tom's book.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I was afraid of that Hopefully returning it won't be too painful. Thanks for the help Christian.
Mark Donkers
A witty saying proves nothing.
-- Voltaire
|
|
|
|
|
Mark, did you get my first or second edition?
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom,
I got the second edition. I haven't had a chance to get into yet I just got off work so I'm going to take a nap, then put on some java and start readin'.
Mark
Mark Donkers
A witty saying proves nothing.
-- Voltaire
|
|
|
|
|
Mark Donkers wrote:
I got the second edition
Cool! I just wanted to make sure you got the latest and greatest.
Mark Donkers wrote:
...then put on some java...
You trying to be funny, Mark?
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
Mark Donkers wrote:
...then put on some java...
You trying to be funny, Mark?
You caught that one. I can C you're quite #.
MD
Mark Donkers
A witty saying proves nothing.
-- Voltaire
|
|
|
|
|
Oh Mark. You are tired. Get some sleep, mate
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
By the way, in conjunction with what Christian said, since both Charles and I write for MS Press, our books are intentionally designed to complement one another. This is why he only has a few pages on C# syntax (while that is almost my entire book) and I don't cover GDI+ at all (where that's the focus of his book). That way, there is little to no overlap. In addition, to mine and Charles' books, you will definitely want to get Jeffrey Richter's book as it goes into a lot of detail with regards to the .NET runtime.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
By the way, Tom, Amazon stitched me up with your book, in that they shipped me the Richter book, but have yet to ship Inside C# 2nd ed ( which frankly was the main one I wanted ). So I don't think they have it to ship yet, I dunno about anyone else though.
I'm sure I'll get it eventually, but I was a bit miffed because I asked them to ship them all at once.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I hate that when you pay someone to screw up Oh well, you should have it shortly as I just got mine in the post.
Thanks for the support!
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
Thanks for the support!
Well, I think I'll be thanking *you* for the support shortly. I'm still a little lost C# wise, at least compared to C++.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I'll be here
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|