|
Another one who really needs to buy a "beginning programming" book.
Seriously, it will help you much much more than we can.
|
|
|
|
|
Hi,
You are confusing two variables both called sum. One is a static class member, the
other is a variable local to Main().
your code is messy.
1. It is inconsistent: the add() method takes two members as input, modifies another member
(result) AND returns a value; to be consistent it would either not return anything (so
it operates on class members only), or it would not touch any members and work with
input parameters and a return value only, which I certainly prefer:
static int add(int v1, int v2) {return v1+v2;}
In this way, there are no "side effects", the method simply does what its name indicates.
2. In general you should use class members only for things that have a permanent significance,
whatever is local to a method should be handled by local variables.
3. rather than making everything (methods, variables) static, it would be much better
to create a class, instantiate it, and forget about the static keyword (except for void Main),
until you really need something that gets shared across all class instances.
Something like this:
class Test {
public static void Main() {
Test test=new Test();
test.Run();
}
public void Run() {
int v1;
int v2;
int.TryParse(Console.ReadLine(), out v1);
int.TryParse(Console.ReadLine(), out v2);
Console.WriteLine("The sum of "+v1+" and "+v2+" is "+add(v1,v2));
Console.ReadLine();
}
public static void add(int v1, int v2) {
return v1+v2;
}
}
Notes:
- there are no class data members at all;
- the static keyword for add() is optional; I use it here to indicatethe method does not
need any class members (and not because it would not compile without the static keyword).
May I suggest you buy a book an C# and work your way through it, it will offer the fastest
and most thorough way to get all the basic knowledge and skills.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Can u recomend any books that are very simple so taht a person who is new to oops can learn C# himself Luc .....
j
|
|
|
|
|
Hi, this is my standard answer on book questions:
Sorry, I can't recommend any books on programming languages. I learned C# many years ago, I bought two books that both are no longer up-to-date (due to C# 2.0). In general I feel book appreciation is very subjective, it depends a lot on your prior knowledge and experience, and your preference for verbose vs. strict description.
I tend to go to the book shop, look at say ten books on the subject and then buy the 1 or 2 that I like most (often one tutorial, one reference manual).
One more comment, I tend to reread the tutorial a couple of times, say with 1 year intervals. A second/third pass through the book always reveals a few useful things that got lost on the first pass.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Microsoft Press Step-by-step series is excellent.
|
|
|
|
|
Thank you guys....
j
|
|
|
|
|
hi all,
I am using a listview to display thumbnail of images with some text. i have used largeicon view to display them.
i have created the thumbnail images and its displayed. as in explorer, i need to have the thumbnail image displayed as a folder. (like a border to the thumbnail and text).
How can i do it? i saw a article here in Codeproject but the code is in VC++.and i am not aware of this.
Is there any way to accomplish the same?
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
Yes there is. First of all you need to set OwnerDraw property of ListView class to true. By doing this you are responsible for providing code for drawing the control. After that handle the ItemDraw event of the listview class to make necessary drawings.
|
|
|
|
|
hi,
Thanks for your help. i have started to use the drawitem event of the listview control and i am making improvement in that.
Thanks for your suggestions.
But could you please provide me with a link
where i might be able to draw a perfect rectangle for the items
using drawitem event?
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
Examine properties of the DrawListViewItemEventArgs parameter that the DrawItem event receives.
|
|
|
|
|
hi,
Thanks for your suggestions.
i have drawn the image and the text using the properties of drawlistitemeventargs(thanks). but still i am not able to figure out how to draw the border for that item.
Could you please help me by suggesting some links?
Thanks once again.
Regards
Anuradha
|
|
|
|
|
The drawlistitemeventargs parameter called e has a graphics property which you use for drawing. So you need to call e.Graphics.DrawRectangle method to draw rectangle around the item. In order to pass the desired rectangle to this method explore e.Bounds property and e.Item.Bounds property. Hope this helps
|
|
|
|
|
hi,
Thanks a lot for your help.
I am able to draw the border now for each item.
Thanks once again.
Regards
Anuradha
|
|
|
|
|
You are welcome
|
|
|
|
|
Hi everybody,
I'm new bie to SCORM and I have to create a project like xmlScormstudio. I have downloaded the project from CVS on http://sourceforge.net/projects/xmlscormstudio. But i can't build it. It seems to be omitted many files. Are there any one know how to build it? Please help me!!!
Thank you!
xyz
|
|
|
|
|
I would suggest that this should be addressed on the project Forum on Sourceforge. I will say, though, that you will probably need CVS to get all of the files.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I have posted the question on the project Forum on Sourceforge, but there seem no one visit it and I downloaded source from CVS
xyz
|
|
|
|
|
I'm sorry. It seems as though the project is dormant then. I don't think anybody here will be able to help.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I'm having a .NET 2.0 application with an application-scoped setting with a default value. Now I'd like to change this settings before starting the application (not in the source). How can I achieve this? I didn't find any file and in the .NET 2.0 configuration tool there's no possiblity to change the settings. I already added the assembly to the GAC and I tried to configure it with the configuration tool.
Thanks in advance, Tobias
|
|
|
|
|
Hi, does anyone know how to use GetAmbientProperty() to get a specific property from the container? I'm talking about custom properties instead of the colour, font etc...
I need to know this because I am trying to develop a custom control to be used in an application (written in VC++6) and the container provides specific details through the use of ambient properties. These details are account name, account number, version numbers and one or two more. I have the Dispatch IDs for these properties but I don't know how to retrieve them in C#.
Thank you for helping!
|
|
|
|
|
If no one knows how to use that ability in C# does anyone know how to do a similar thing in C#?
|
|
|
|
|
Hi,
I am sending data in the form of a COPYDATASTRUCT to a second application using the SendMessageTimeout() API function. The data is sent accordingly and the COPYDATASTRUCT retrieved at the other end using Marshal.PtrToStructure. I would now like to pass back a new COPYDATASTRUCT in the Message.Result, I do this with the following:
<br />
Win32.COPYDATASTRUCT cds = new Win32.COPYDATASTRUCT();<br />
cds.dwData = 1;<br />
cds.lpData = mydata;<br />
cds.cbData = Win32.GlobalSize(cds.lpData);<br />
<br />
IntPtr pResult = Marshal.AllocCoTaskMem(Marshal.SizeOf(cds));<br />
Marshal.StructureToPtr(cds, pResult, true);<br />
m.Result = pResult;<br />
Now the correct IntPtr value is passed back in the result param of the SendMessageTimeout function but when I try to retrieve the structure using Marshal.PtrToStructure() all 3 members of the strucure are zero.
I'm sure I'm missing something obvious here but I've been staring at it for hours and can't seem to see the problem.
|
|
|
|
|
I'm guessing you are sending a WM_COPYDATA message (with your COPYDATASTRUCT) to the other application. In general, Windows keeps each application in it's own virtual memory space. This virtual memory space is completely independent of other applications. So if you allocate memory in application#1, then the pointer returned is only good for application#1.
If you look at the MSDN[^] documentation for WM_COPYDATA, the first line under Remarks states that "The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data". Because pointers are only valid for the given application. You can pass the memory location (a.k.a. the pointer's value) to another application, but the other application cannot do anything with it.
To copy data back, you would have to send a WM_COPYDATA message back to the first application. You could also use named pipes[^], .Net remoting, or maybe this[^].
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi to all,
I am trying to delete all the files in a specified folder in my project. for that i have written the following function....
==============================================================================
Code
==============================================================================
public void DeleteTempFiles()
{
DirectoryInfo DirInfo = new DirectoryInfo(Server.MapPath("~/temp/"));
if(DirInfo.Exists)
{
foreach (FileInfo FI in DirInfo.GetFiles())
{
FI.Delete();
}
}
}
==============================================================================
But whenever i am running the program it gives the error as....
Error Deleting File or Folder
Cannot delete <filename>: It is being used by another person or program.
Close any program that might be using the file and try again.
.....
Anybody help me to solve this problem.
Pravin
|
|
|
|
|
It means that the file you want to delete is in use either by your program or by other programs. If your program has an open handle to the file then close it.
|
|
|
|