|
Ahh.... i see...
Sorry, I'm new. Every post I post here is like an awakening.
Appreciated,
Matt
|
|
|
|
|
Ahhh... much better... dang datatypes.
RegistryKey myRegKey = Registry.CurrentUser;<br />
myRegKey = myRegKey.OpenSubKey("Software\\Microsoft\\Windows\\Shell\\Bags\\1\\Desktop\\");<br />
String[] valueNames = myRegKey.GetValueNames();<br />
<br />
string[] OriginalValueName = new string[valueNames.Length];<br />
int[] OriginalValueData = new int[valueNames.Length];<br />
<br />
int i = 0;<br />
foreach (String valuename in valueNames)<br />
{<br />
MessageBox.Show(valuename);<br />
OriginalValueName[i] = valuename;<br />
<br />
Object ovalue = myRegKey.GetValue(valuename);<br />
MessageBox.Show(ovalue.ToString());<br />
<br />
OriginalValueData[i] = (int)ovalue;<br />
<br />
}
|
|
|
|
|
Hi,
int may be sufficient, it depends on what you want to do with the data afterwards.
One potential problem is you don't store the original type information, so a key (Paul, 123) may have been a REG_BINARY or a REG_DWORD, so you would not be able to restore registry entries lacking some information.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Ahh okay... I'll store that as well.
Can I store different data types per-dimension in a multi-dimensional array?
|
|
|
|
|
bbranded wrote: Can I store different data types per-dimension in a multi-dimensional array?
No. (i.e. not in the simple way you probably are thinking of; you can as structs/class objects, but then you wouldn't need extra dimensions any more).
Object oriented principles would tell you to store all information about one real-life object (such as a registry key) into one software object, that is why I suggested you make your own type (struct or class) in the first place.
FWIW: It may be wise to buy and study a book on C#, that would give you a head start by teaching you all the relevant principles, explaining them well and illustrating them with examples.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks very much for all of the info.
People keep telling me that I need basics.... hah! Maybe one day...
The data type/struct thing seems very interesting to me, and makes perfect sense.
I'm always getting in over my head... my primary job (and my skill set) is a network and sys admin. I code on the side, and I feel like I'm slowly slipping into coding more... maybe I should buy a book.
Thanks!
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
try using ArrayList in System.Collection namespace you don't even have to check for a type because this collection stores them as objects
for your case
ArrayList OriginalValueData=new ArrayList();
for(...)
{
OriginalValueData.Add(OValue);
}
I hope that would solve ur probles
Good Luck
|
|
|
|
|
|
Hi
I want to write a message to the text file as soon as the server starts.I have written the following code which creates a new file but it does not write anything into it.I tested this code by starting only one server.It does not work.Please help me find where i went wrong.proclist contains the list of all servers.
foreach (Process pr in proclist)
{
if (!File.Exists("logfile.txt"))
{
stw = new StreamWriter("logfile.txt");
}
else
{
stw = File.AppendText("logfile.txt");
}
DateTime started = pr.StartTime;
stw.WriteLine("Server information:");
stw.WriteLine(started.ToString());
}
|
|
|
|
|
Hi,
stw.Close(); ??
or possibly
stw.Flush();
stw.Close();
Although it might be simpler to forget the StreamWriter and use
File.AppendAllText("logfile.txt", String.Format("Server Info:\r\n {0}\r\n", started));
Alan.
|
|
|
|
|
Yes it seems like Flush() is missing.
But for logging you should better use log4net[^].
It is very easy to configure and start writing log messages.
Vitaliy Tsvayer
Tikle
|
|
|
|
|
hi
Thanks now im getting it right
|
|
|
|
|
hello everybody
i need to build a small program in C# that searches within a C source code (a txt file basically) for variables and method names and after that to replace them with something else. i can't do the first part. i've tried to do something but with no success. can you help me with some informations/suggestions?
thank you in advance
|
|
|
|
|
You must know all the keywords that can come before a variable or method name, like int, string etc. You will also need to check if the word there for variable declaration and elsewhere. ie word string might come in a comment text and then you will end up editing the comment.
All I can suggest is to make sure you know what I have written above. Then you can just take the very next word and replace it.
जय हिंद
|
|
|
|
|
list the possible keywords, and try building a regular expression for them, since every line should end with ";" it might loosen writing the a regular expression for it, but it will be a lil tough.
good luck
|
|
|
|
|
When I populate properties in my classes, I usually use reflection to get values from a DataReader and set the values. What do you guys think of this technique? Below is a snipplet:
SqlDataReader dr = new SqlDataReader();
PropertyInfo[] properties = this.GetType().GetProperties();
dr.Read();
foreach (PropertyInfo pf in properties)
{
pf.SetValue(this, dr[pf.Name], null);
}
|
|
|
|
|
Fayu wrote: What do you guys think of this technique?
It's brilliant. Have you applied for a patten yet?
|
|
|
|
|
Thanks. I have been using this technique for many many years now. I always wondered if there was a performance penalty or other types of penalties when using this method. I never encountered any problems. I wanted to see what the experts had to say.
|
|
|
|
|
Fayu wrote: I wanted to see what the experts had to say.
No you don't, that's twittering garbage. If your statement was true you would be reading the Microsoft Documentation rather than posting your garbage in internet forums.
|
|
|
|
|
If you think my posting is garbage, you did not have to respond.
|
|
|
|
|
Fayu wrote: you did not have to respond.
How do you know what I have to do? Oh right, you're one of those guys that just knows stuff huh?
|
|
|
|
|
I think this is a bit odd, and reflection is generally quite slow
|
|
|
|
|
Fayu wrote: What do you guys think of this technique?
Not sure. Why would you do it this way? Does it offers something good?
जय हिंद
|
|
|
|
|
I used this in a base class. When I inherited the base class in other classes, I did not have to worry about populating their properties (or performing other logic), the base class would do it. The other classes that inherited the base class were 'templates'.
|
|
|
|