Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 5th, 2003, 03:28 PM
Registered User
Join Date: Jul 2003
Location: Calgary, AB, Canada.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to megabytes
Default Help with Functions

Here is the my code but I get an error saying "An object reference is required for the nonstatic field, method, or property Getname.function1(string, string" HELP!!!! :)


class Getname

            public static void Main(string[] args)

                  Console.WriteLine("Please enter your first and last name with one space");
                  string userName = Console.ReadLine();

                  Console.WriteLine(" ");

                  char[] separator = {' '};
                  string[] fullName;

                  fullName = userName.Split(separator);

                  string firstName = fullName[0];
                  string lastName = fullName[1];

                  char[] firstLetter = firstName.ToCharArray();

                  function1 (fullName[1], fullName[0]);
                  function2 (firstLetter[0], fullName[1]);


            public void function1 (string lastName, string firstName)
                  Console.WriteLine("{0}", lastName + ", " + firstName);

            public void function2( char firstLetter, string lastName)
                  Console.WriteLine("{0}", firstLetter + "." + " " + lastName);



Reply With Quote
  #2 (permalink)  
Old August 7th, 2003, 12:48 PM
Authorized User
Join Date: Jun 2003
Location: Gainesville, FL, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts

Quick $0.02:
Maybe you should have a constructor for Getname, and have your Main call it
( Getname gn = new Getname(); in the Main routine).
I think the problem is that function1 is a Method (i.e. a member) of Getname, and in truth it is a non-static member. Thus, you are able to call function1 (and function2) only if you have an instance of Getname. So
 Getname gn = new Getname();
 gn.function1("foo", "bar");
should work.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C functions...??? ethantinder C# 2 April 25th, 2008 02:25 AM
Functions LTello BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 September 15th, 2006 11:15 AM
Functions czambran BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 13 July 11th, 2006 06:33 PM
functions xelepi PHP How-To 1 March 10th, 2006 02:59 AM
Functions Meg Intro Programming 1 January 23rd, 2006 01:03 PM

All times are GMT -4. The time now is 05:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.