Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2007, 01:54 AM
Authorized User
 
Join Date: Jul 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Very Simple Question

How do you create and store codes such as methods in a new .cs file (Request.cs) and then call the code in there on an event on a form?

 
Old May 4th, 2007, 02:04 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Create your file and, assuming you are using instance members (as opposed to static) you would do something like:

private void btn_click(Object sender, EventArgs e)
{
     Request rq = new Request();
     rq.someMethod();
}

using static members:
private void btn_click(Object sender, EventArgs e)
{
     Request.someStaticMethod();
}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 4th, 2007, 02:23 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can't just create functions, you need to create them as methods in a class. In Request.cs create a public class called Request. Add some methods such as DoSomething(). If they are declared as static methods then you can call Request.DoSomething() from your form. If they are instance methods you need to instantiate a Request object:
Code:
Request req = new Request();
req.DoSomething();
--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
not at all simple question petergoodman XSLT 0 July 18th, 2008 08:37 AM
Simple Question ironchef Java GUI 0 September 14th, 2006 04:56 PM
Simple Question dpkbahuguna Java Basics 2 May 19th, 2006 12:05 AM
Simple question happyheart_man Pro VB.NET 2002/2003 0 January 14th, 2004 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.