|
shwaguy wrote:
Classes: What should go into a class and what should stay out?
Everything in C# MUST be in a class.
shwaguy wrote: Should my class for this return the processing results
and
shwaguy wrote: Is it acceptable to have a class return some result but then call on the same class
Classes in C# can not return values, methods (functions) and properties (think externally accessible variable) can.
shwaguy wrote: Should I just forget about "functions" and "sub-routines" and throw everything into classes?
your functions have to be contained in a class
For an example all of these sources do the same thing
namespace myApp
{
class mainclass
{
static void Main(string[] args)
{
My_Function_();
}
public static void My_function_()
{
Console.WriteLine("My \"Function\" was called");
}
}
}
namespace myApp
{
class mainclass
{
static void Main(string[] args)
{
myclass.My_Function_();
}
}
class myclass
{
public static void My_function_()
{
Console.WriteLine("My \"Function\" was called");
}
}
}
namespace myApp
{
class mainclass
{
static void Main(string[] args)
{
anothernamespace.myclass.My_Function_();
}
}
}
namespace anothernamespace
{
class myclass
{
public static void My_function_()
{
Console.WriteLine("My \"Function\" was called");
}
}
}
|
|
|
|
|
SpacixOne wrote: Everything in C# MUST be in a class.
What about Structures?
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
Well, there wasn't a question about a struct... but
A structure can't inherit from a class (and vice versa) and a struct is created then dies when reaching the closing brace. It is a different animal but no it doesn't have to be defined within a class, but if you use it (write or read a member) that HAS to be inside a class...
More C# syntax can be found here http://msdn2.microsoft.com/en-us/library/618ayhy6(vs.80).aspx[^]
|
|
|
|
|
shwaguy wrote: What should go into a class and what should stay out?
In: Students who have an aptitude for the subject and really want to learn.
Out: Students who think the subject is an "easy A" and that "anyone can do it".
|
|
|
|
|
OK,
So the message I seem to be getting is that, anything can be done from anywhere as long as it works. So if it seems write to have MyClass.Function0 return a value and dump that value to a file it is technically OK.
Aside from logical organization is there anything style wise I should know? For instance it would not seem right to have MyClass.Function both return a value and print those same values; I seems right to have a seperate class.function take the return values from MyClass.Function and do the writing. That would allow me to have multiple funcitons access my file writing function and eliminate repeat code.
Is that right?
The shwa guy
|
|
|
|
|
Hi,
my programm reads/writes an xml file. Here is how:
Open file
read
Close file
Open file
write
Close file
Yes,it's necessary that way. My problem is, when I open the Windows Explorer (WinXp sp2) and look into that folder, after some time i get an exception that the file is openend partially by an user.
This happens EVERYTIME at the same codeline: doc.save(myfile) (doc = xmlDocument).
Why is that happening?
Can i prevent that? If not, how can i handle that exception, without Thread.sleep loops?
Please help me!
|
|
|
|
|
You might have left off the <pre></pre> tags and we can't see the code you posted...
|
|
|
|
|
|
Ah, just looked like you did.
is this being done in < .NET 2.0?
|
|
|
|
|
Yes .Net 2, i tried to convert and compile it with .net 3 but same thing happened.
|
|
|
|
|
Are you using the old xmlreader and xmlwriter?
If not then why do you "open, read, close" then "open, write, close" ?
|
|
|
|
|
I'm using the xmlDocument Class. When i want to save with xmlDocument.save() that error happens
|
|
|
|
|
Im willing to bet that you've not disposed properly of the stream when you open the file, hence when you come to write it there is already another process holding onto it (ie, your own program from earlier on during the read op)
|
|
|
|
|
Thats not the case, because it does not happen at all if i don't open the explorer and look into that folder.
|
|
|
|
|
once you call the load() method the file should no longer be accessed...
Again I don't see why you "open, load, close" then "open, write, close"
You should be fine with it in ram after you load it. "open, load" do your other stuff "append new data, close"
|
|
|
|
|
I tried it. But it doesn't have an effect.
Here is my code at the moment:
XmlDocument doc = new XmlDocument();
doc.Load(FullFilePath);
.......
doc.Save(FullFilePath);
|
|
|
|
|
Does it error if you try to write to a different file path? (one you know you have write access to)
|
|
|
|
|
Hi,
if you want write or delete access (anything other than read access) to a file
that just got created (by yourself or someone else, does not matter),
chances are you will find the file is being accessed by some other process,
and your access is not granted.
Yhe other process very likely is some server code that is there to assist you
somehow. Candidates are:
- anti-virus software (Norton, McAfee, whatever)
- indexing software (Google Desktop, MS Office, whatever)
The common thing is these packages are looking all the time for new files, so
they can inspect them.
Microsoft is aware of the consequences; Windows Explorer will try rename and
delete attempts up to five times (with one second interval), and only reports
failure if the action continues to fail for that time.
The solution:
1. either use a different file name
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer
for this)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thank you very much.
Luc Pattyn wrote: The solution:
1. either use a different file name
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer
for this)
1. and 2. are no solutions for me.
I have to try 3. I think. I hoped i don't have to use a timer
|
|
|
|
|
hello everyone...
my problem is that there are some people who will only use asp.net page to chat. a group of people will chat those asp.net chatters from windows application. i mean how can i acvhieve this chat between c# and asp.net. can anyone help please
|
|
|
|
|
_beginner_ wrote: i mean how can i acvhieve this chat between c# and asp.net
ASP.NET is a framework. C# is a language that can be used to write ASP.NET applications. Are you asking how to communicate between the ASPX page and the code behind?
If not then you really need to explain better because I don't understand what you are asking.
|
|
|
|
|
the problem is this. some people must use aspx web page to chat. and some people must use a windows application like msn messenger. for exmple, i will use msn messenger to chat with you, and you must use an aspx web page to chat with me. maybe this is more clear
|
|
|
|
|
It can be done, and the general practice is to have a central server with 2 types of client:
web: pings for new messages (possibly using AJAX)
windows: gets messages pushed to it from server.
Start with an example of a straight windows forms chat application - there will be plenty online - and build the web client when you are more knowledgable on cthe chat software.
|
|
|
|
|
how windows app users know that there is a messge from web app users same problem for web users..
someone advice me to use socket programming. is it posible.
|
|
|
|
|
At the moment how does one windows app user know there is a message from another windows app user?
|
|
|
|