|
Hi,
if you are familiar with older languages such as C, it is very similar:
1. simple things (int, double) get copied (pass by value);
2. for complex things (strings, class instances) a pointer is passed (so there is no object
copied, it is the same object you get). Whether you call this by value or by ref however
is a bit confusing (you can optionally add a ref keyword to increase the level of indirection
by one)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you all for your reply. It really helped me to understand this concept.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
I m new in C# please give me code for datageid conectivity with database.
Thanx in advance
help as a alias.
Be happy and make others happy.Cheer up...........
|
|
|
|
|
Use google for this also in codeproject you can get multiple articels
Keyword to search DataGrid+databind
Sarvesh Upadhyay
Senior Software Engineer
Birlasoft India Ltd.
Microsoft Certified Professional Developer in Dotnet 2.0 Enterprise Application
|
|
|
|
|
thanx
help as a alias.
Be happy and make others happy.Cheer up...........
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string yazi;
Console.WriteLine("Dosya Ismini Giriniz");
Console.WriteLine("Örnek: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader dosyaOku = File.OpenText(inFile);
yazi = dosyaOku.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
while (yazi != null)
{
if (yazi.StartsWith(onEk))
{
string gecici = yazi.Replace(onEk, "");
string[] parcalar = gecici.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(string.Format("{0}\n{1}\n{2}", parcalar[0], parcalar[1], parcalar[2]));
i++;
}
yazi = dosyaOku.ReadLine();
}
Console.ReadLine();
dosyaOku.Close();
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
sw.WriteLine(string.Format("{0}\n{1}\n{2}", parcalar[0], parcalar[1], parcalar[2]));
sw.Flush();
sw.Close();
}
}
ERROR:(37,53): error CS0103: The name 'parcalar' does not exist in the current context
I want to write to text file after file is readed(modicificated) that is , I want to write output data but I cant be able to
|
|
|
|
|
It means that you've declared parcalar in the wrong place. Move the declaration to before the while and it will be visible. So, you get
string[] pacalar = null; However, you do know that you are only going to write one line to the file don't you?
|
|
|
|
|
"However, you do know that you are only going to write one line to the file don't you? "
mr.pete as your told it is writed one line to the file but i want to as a column by reading all line. please help me.
sample:
1456
4596
122.2
145.4
|
|
|
|
|
Move the declaration of the streamwriter before the while loop, and write to it when you need to then close it afterwards.
|
|
|
|
|
I test to your said but this time code isnt run (
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string yazi;
Console.WriteLine("Dosya Ismini Giriniz");
Console.WriteLine("Örnek: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader dosyaOku = File.OpenText(inFile);
yazi = dosyaOku.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parcalar = null;
while (yazi != null)
{
if (yazi.StartsWith(onEk))
{
string gecici = yazi.Replace(onEk, "");
string[] parcalar = gecici.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(string.Format("{0}\n{1}\n{2}", parcalar[0], parcalar[1], parcalar[2]));
i++;
}
yazi = dosyaOku.ReadLine();
}
Console.ReadLine();
dosyaOku.Close();
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
sw.WriteLine(string.Format("{0}\n{1}\n{2}", parcalar[0], parcalar[1], parcalar[2]));
sw.Flush();
sw.Close();
}
}
firstly thanks for help you.
later ERROR:(28,26): error CS0136: A local variable named 'parcalar' cannot be declared in this scope because it would give a different meaning to 'parcalar', which is already used in a 'parent or current' scope to denote something else
called file contents:
Frequencies -- 1093.5623 1094.7121
Red. masses -- 6.4909 1.3756
Frc consts -- 4.5735 0.9713
Frequencies -- 0.0002 0.0400
Raman Activ -- 0.0000 0.0000
Depolar (P) -- 0.7162 0.6260
Frequencies -- 0.8346 0.7700
output data
1093.5623
1094.7121
0.0002
0.0400
0.8346
I want to write to a file, "OUTPUT DATAS"
|
|
|
|
|
You've decalred the variable parcalar twice, although in different scopes. The problem is the compiler would have no way of knowing to which you were refering so it will give you that compile time error.
Remove the 'string[]' from the second declaration.
Also try using pre tags with code to preserve indenting. You'll get more help.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hi all,
I am looping through a series of directories moving files fom one place to another, this i haven't got a problem with.
My query finds all files and moves them without a problem with the exception of all the .zip files.
This has me stumped.
I can get the FileInfo for the zip files and response.write the name onto the page, so I know they're being found, however the File.Copy isn't moving them.
I am running the query under an if (FileName.Extension.toString() == ".zip")
which works for writing the name, just not copying the files?
Please help if you can, many thanks in advance
Mark
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
File.Copy(@"C:\Demo2.zip", @"C:\NewDemo2.zip");<br />
}
Seems to work fine with me....
|
|
|
|
|
Here's a tip: Learn how to debug. It will be far more efficient than posting a question in a forum every time something like this happens.
led mike
|
|
|
|
|
Hi All,
I thought it would be simple solution but not really being able to crack it.
I have a webservice which acts as data provider to the client which is a windows application. The webservice has various web methods and I have written them in a way that they share same SQLTransaction object while retrieving data.
WebService has BeginTransaction(), CommitTransaction() and RollbackTransaction() methods. when I want to perform an operation (which typically consists of 3/4 webmethod calls) I call BeginTransaction() first and CommitTransaction() or RollbackTransaction() after the operation is finished or in case of exception.
The problem:
If the user makes the application to end using task manager after BeginTransaction() has been called and before CommitTransaction() or RollbackTransaction() is called. When next time the application is launched, it fails to fetch data and gets stuck attempting to retieve it. This is because the previous transaction is still locking the tables!
Well, It might take long to read the post but I thought it was important to explain it in detail.
Can anyone think of any way out?
Thanks in Advance
AD
Every bit counts
|
|
|
|
|
The odds of that happening are EXTREMELY Slim...
It's like the "If x is saving, and I have a Power Failure, then it crashes next time it starts up."
type of question.
Although, maybe in your case you could have a true / false setting which decides if the transaction is in process, with a timeout. If it expires, it automatically rolls back.
Just an idea
- Reelix
|
|
|
|
|
Thanks for reply.
The problem is I dont have anything to check even if I use true/false. The application has been closed and it doesnt even know that it is being closed down. I dont get any event when the application is closed using task manager.
AD
Every bit counts
|
|
|
|
|
Hi!
I am making an asp.net c# application (dotnet framework 3.5), where I am trying to update RegistryKeys on computers in the local area network at my company.
When executing OpenRemoteBaseKey() on one of the computers (running Vista), this:
RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
MachineName);
results in an IOException: "The network path was not found.\r\n"
When I try executing OpenRemoteBaseKey() on another (running win 2000), the OpenRemoteBaseKey operation works fine, but then the
CreateSubKey() fails in an UnauthorizedAccessException "Access to the registry key 'HKEY_LOCAL_MACHINE\\SYSTEM\\..' is denied."
I can run both on my local computer with no problem, so the application obviously lack rights(?) in performing the operations, hence my question is how do I set the access rights in order to be able to update these keys on all computers in the network, meaning running this with no problem:
RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, MachineName);
RegistryKey newKey = regKey.CreateSubKey(RegistryPath);
newKey.SetValue("mycomment", myText);
?
Regards,
Heidi H.
heidihundala@gmail.com
|
|
|
|
|
heidihund wrote: The network path was not found.
Are you sure that the machine name is correct? If it is, does the client allow remote registry access? If it's saying it can't find the network path my suspicion is the path is incorrect, or a firewall is blocking it.
|
|
|
|
|
Yes. The name is correct.
I don't think the firewall is blocking it, but the security is probably the issue, hence
I wonder if there is another way of changing the registry value remotely, where e.g. it is possible to set the username and password when accessing the registry, in order to have the security settings in order? I have gotten some hits on WMI, but I haven't found a way to do this in csharp yet.
Regards,
Heidi
heidihundala@gmail.com
|
|
|
|
|
The only way I can think of is to log on before hand because I just wrote a simple piece of code to access the registry on my Windows 2003 server which is running under the default tied down settings. It worked fine and my laptop and server on different domains but I am logged onto the server to access files and my account which I'm logged in under is a Domain Administrator group so...
|
|
|
|
|
I found a solution which is with not using OpenRemoteBaseKey(), and where you "log on" in a Connection before the change:
System.Management.ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "username";
oConn.Password = "pwd";
oConn.EnablePrivileges = true;
ManagementScope oMs = new ManagementScope(string.Format("\\\\{0}\\root\\default", MachineName), oConn);
oMs.Connect();
if (oMs.IsConnected) {
ManagementPath Path = new System.Management.ManagementPath("StdRegProv");
ManagementClass objClass = new System.Management.ManagementClass(oMs, Path, null);
ManagementBaseObject objInParams = objClass.GetMethodParameters("GetStringValue");
objInParams["hDefkey"] = LOCAL_MACHINE;
objInParams["sSubkeyName"] = KEY_NAME;
objInParams["sValueName"] = "NameOfRegKey";
ManagementBaseObject outParams = objClass.InvokeMethod("GetStringValue", objInParams, null);
objInParams = objClass.GetMethodParameters("SetStringValue");
objInParams["hDefkey"] = LOCAL_MACHINE;
objInParams["sSubkeyName"] = KEY_NAME;
objInParams["sValueName"] = "NameOfRegKey";
objInParams["sValue"] = "My value";
objClass.InvokeMethod("SetStringValue", objInParams, null);
}
Regards,
Heidi
heidihundala@gmail.com
|
|
|
|
|
Also, the code is running as the ASPNET user on the server, which doesn't have any permissions to any other machine. So, the most it's going to be able to do is look at the values under a remote HKEY_LOCAL_MACHINE hive. It won't be able to modify anything.
Unless, of course, you run the ASP.NET app on the server under a domain admin level user account, but that's a huge security risk...
|
|
|
|
|
I am developing a game the contains ball and blocks and i want the ball to break the blocks upon collision with the ball and also to award marks after every collision
The background color should fill the space of the ball
|
|
|
|