NonVisual Help Needed (I have such a headache)

L

LC

I am learning C# .net and am working with Visual C# .net package.

I am trying figure out how to create a nonvisual object that can
contain functions/methods that would be called to enforce business
rules.

After reading oh so many posts I am still not sure.

Do I create a new class by going to File\Add New Item?
If so, how do I add functions/methods to this object? I am guessing I
have to do it by writing code as opposed to something in the
development environment I could just click on(wishful thinking?).

I am coming from a Powerbuilder environment so the ideas are the same
but just implemented differently.

I appreciate your assistance.
 
O

Oddball

I'm going to try and help you out here without sounding like a bit of an ass :S It's late
so PLEASE excuse me if I offend.

The answer is yes - File-->Add New Item...-->Dialog box gubbins = new class file.

But if you are lacking the knowledge of how to structure a class and add methods,
members and other hoojemahwhotsits you're digging for Oz with a spoon.

Try using Google to find some information about class structure in C# - or even better
head over to Amazon and get yourself a book. I recommend anything by O'Reilly (they
can send me the check when they read this).

As a brief guide:

<access modifier> <return type> <name> ( [params])
{
// Some code in here
}

public void EnforceRule(int ruleNumber)
{
// do the enforcing
}

If I've been driveling then like I say - don't blame me, it's late :D


LC said:
I am learning C# .net and am working with Visual C# .net package.

I am trying figure out how to create a nonvisual object that can
contain functions/methods that would be called to enforce business
rules.

After reading oh so many posts I am still not sure.

Do I create a new class by going to File\Add New Item?
If so, how do I add functions/methods to this object? I am guessing I
have to do it by writing code as opposed to something in the
development environment I could just click on(wishful thinking?).

I am coming from a Powerbuilder environment so the ideas are the same
but just implemented differently.

I appreciate your assistance.


------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
 
B

Bob Grommes

Hi LC,

I assume you're using Visual Studio 2003 ... here are some options for you.

Let's assume you have a very simple project with one source file, Main.cs.

You could:

1) Just declare another class in Main.cs and code it out.

2) Right-click on the solution in Solution Explorer, Add | New Project.
Define your class in that new project. Add a reference to that project in
your original (startup) project. If you used a different namespace than
your original project, and you reference the class in your original project,
then you'll want to add an appropriate "using" statement to the top of
Main.cs.

You would typically do (1) if the class is just going to be used by Main.cs,
or (2) if you expect to use it in multiple projects or solutions over time.
With (2), your new class will be in its own DLL. With (1) it'll be part of
your EXE.

If you did (1) then Main.cs would look something like this:

using this;
using that;
using System;

namespace Main {

class MainClass {
// definition
}

class MyAddedClass {
// definition
}

}



As soon as the new class is coded, it should show up in Intellisense when
you reference it elsewhere. If it doesn't, then generally you've forgotten
to reference it or provide a using statement.

3) is a varaition on (1) -- as you suggested, you could right click on your
original project, Add | New Class and code the class in a separate source
code file from Main.cs. Other than that it's no different than (1). It's
strictly a matter of how you want to organize your source files. In
general, for any non-trivial project, you'll tend to add .cs files for major
classes or groups of smaller classes. And you'll do separate projects for
classes that would be apt to be reused in different solutions.

That's it -- a little simplified but should get you started.

--Bob
 
J

James Curran

Bob said:
You could:

1) Just declare another class in Main.cs and code it out.

2) Right-click on the solution in Solution Explorer, Add | New
Project. Define your class in that new project. Add a reference to

There's an option in the middle (which would be my choice). Right-click
on the *project* in Solution Explorer, and choose "Add|New Class"
 
B

Bob Grommes

That would be option (3) toward the bottom of my missive ;-)

--Bob

James Curran said:
Bob said:
You could:

1) Just declare another class in Main.cs and code it out.

2) Right-click on the solution in Solution Explorer, Add | New
Project. Define your class in that new project. Add a reference to

There's an option in the middle (which would be my choice).
Right-click on the *project* in Solution Explorer, and choose "Add|New
Class"

--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top