Results 1 to 5 of 5

Thread: Simple Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    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!

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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???

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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
  •  



Click Here to Expand Forum to Full Width