|
-
Feb 13th, 2004, 02:04 PM
#1
Thread Starter
Fanatic Member
Simple Question
I am a vb dev trying to understand c# syntax. If I want to call a function from main (should I be doing this) how would I do it? Here is my code:
Code:
namespace parsetxt
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string parsed = parseIt("lease.txt");
//
// TODO: Add code to start application here
//
}
public string parseIt(string fl)
{
// Read the file as one string.
System.IO.StreamReader myFile =
new System.IO.StreamReader(fl);
string myString = myFile.ReadToEnd();
myFile.Close();
// Display the file contents.
Console.WriteLine(myString);
// Suspend the screen.
Console.ReadLine();
}
}
}
Thanks!
-
Feb 13th, 2004, 02:16 PM
#2
You did it correctly, but you have no object to work on. Make parseIt static, then it will work.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 13th, 2004, 02:17 PM
#3
Thread Starter
Fanatic Member
Is it better practice to not have any functions within your main class (where the main function resides). Would it be better to create a new class, and place functions in there???
-
Feb 13th, 2004, 02:25 PM
#4
OOP design is about larger things than just "where put the functions". If you think function-wise, then an OOP language like C# is not for you. You first need to learn the object oriented programming concepts to understand what a class is about.
If you don't use Internet Explorer, you can look at this, it explains the theory of oop.
http://stud3.tuwien.ac.at/~e0226430/...heory_main.xml
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 13th, 2004, 02:45 PM
#5
Thread Starter
Fanatic Member
Well, I think I do understand some of the concepts. But, I will agree that I am rusty on why it is such a benefit from event driven programs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|