473,769 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner Confusion - C# Terminology - Simple Function as Example

Sorry for the simple question but thanks in advance:

My goal is to create reusale code for a web app in C#.
I have written the code already as a windows app but here is where I am
confused:

To keep it really easy let's say this is the code:

function addition(int, int);
int X;
int Y;
int Z = x + y;

return Z;

I want to be able to have this "program" as "compartmentali zed" code so
I code reuse it whenever I need....

Do I:
1. use this as a function?

2. and does the function need to be in a class?

3. how would I "save" this code in some way to use in Application1 or
Application2. Does it get called as a Class or a Function?

4. Do I need to create a Class Library or .DLL? and how does this
relate to namespaces?

5. If we then go to ASP.NET, how would I implement it as reusable for
the web? I could create the form and then use the onSubmit but do I
call the function the class or the .dll?

6. And if I wanted to use it in more than one website, is there a way
to bundle the function as well as the HTML needed to execute it?

////////
Header and encoding info.......
<p>This is the addition sample.
</p>
<form name="form1" method="post" action="">
<p>
<input type="text" name="textfield ">
Enter X</p>
<p>
<input type="text" name="textfield 2">
Enter Y</p>
<p>
<input type="submit" name="Submit" value="Add">
(plus the function or class, .dll?)</p>
<p>
<input type="text" name="textfield 3">
This is returned Z</p>
</form>
//////////////////

Thanks SO much. I REALLY appreciate any and all help!
-Ranginald

Apr 7 '06 #1
4 2660
In C# every method must be inside a class or structure.
You can't have a method (function) in a file and then use it.

Class library compiles to a .NET DLL

So if you would like to use one class in multiple projects then make a
class library project put your code there compile the code and then
refrence the dll from other projects. That way you can use your class
like any other class that you have written (or is included with .NET)

It seems that you are confused as you don't quite distinguish a method
from a class and class from dll.
Maybe you should read some beginner books before you start working on
some projects?
lp
Jan Hancic
http://cwizo.blogspot.com

Apr 7 '06 #2
Hello,

In C#, there is no such thing as "standalone functions" All "functions" must
be members of a class.
So the simplest version of your code would be as follows:

public class Math
{
public static int Addition(int x, int y)
{
return x + y;
}
}

You can compile this class as part of dll, using class library project, and
use it from any other project.
Your confusion between classes and functions scares me a little bit. Class
is a pattern describing instance behavior (methods) and data (fields), while
function is, well, everyone knows what a function is (I hope so)
Namespaces are there just to separate logical parts of code, said freely, so
dlls are in no way related to namespaces.
You can reference dlls made as class libraries from asp.net and finally,
yes, there is a way to deploy (bundle) the web site code along with
referenced assemblies.

"Ranginald" <da*******@gmai l.com> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com.. .
Sorry for the simple question but thanks in advance:

My goal is to create reusale code for a web app in C#.
I have written the code already as a windows app but here is where I am
confused:

To keep it really easy let's say this is the code:

function addition(int, int);
int X;
int Y;
int Z = x + y;

return Z;

I want to be able to have this "program" as "compartmentali zed" code so
I code reuse it whenever I need....

Do I:
1. use this as a function?

2. and does the function need to be in a class?

3. how would I "save" this code in some way to use in Application1 or
Application2. Does it get called as a Class or a Function?

4. Do I need to create a Class Library or .DLL? and how does this
relate to namespaces?

5. If we then go to ASP.NET, how would I implement it as reusable for
the web? I could create the form and then use the onSubmit but do I
call the function the class or the .dll?

6. And if I wanted to use it in more than one website, is there a way
to bundle the function as well as the HTML needed to execute it?

////////
Header and encoding info.......
<p>This is the addition sample.
</p>
<form name="form1" method="post" action="">
<p>
<input type="text" name="textfield ">
Enter X</p>
<p>
<input type="text" name="textfield 2">
Enter Y</p>
<p>
<input type="submit" name="Submit" value="Add">
(plus the function or class, .dll?)</p>
<p>
<input type="text" name="textfield 3">
This is returned Z</p>
</form>
//////////////////

Thanks SO much. I REALLY appreciate any and all help!
-Ranginald

Apr 7 '06 #3
Thanks so much.
I tried it and it worked.
I was able to create a class library containing the Math Class and the
Addition Method, compile it as a .dll and then reference it in another
project.

This may be way ahead but is an ASP.NET server control similar in
concept to the delployed code and assemblies you mentioned? If this is
way too big a question to explain I understand.

Thanks again.

Apr 8 '06 #4
Yes, everything in .net is a class(object) in .dll(assembly).
"Ranginald" <da*******@gmai l.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Thanks so much.
I tried it and it worked.
I was able to create a class library containing the Math Class and the
Addition Method, compile it as a .dll and then reference it in another
project.

This may be way ahead but is an ASP.NET server control similar in
concept to the delployed code and assemblies you mentioned? If this is
way too big a question to explain I understand.

Thanks again.

Apr 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3686
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a crystallization of style. Languages such as APL, Lisp, and Smalltalk are what you might call style...
44
4281
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there must be many know the answer here. thanks
9
1371
by: vidalsasoon | last post by:
Ok, this is the structure of my classes. " class Global " | " ------------------------------------------- " | | "class SomeForm1 class SomeForm2
13
1713
by: sathyashrayan | last post by:
Dear group, pls go through the following function definition: function at_show_aux(parent, child) { var p = document.getElementById(parent); var c = document.getElementById(child); var top = (c == "y") ? p.offsetHeight+2 : 0; var left = (c == "x") ? p.offsetWidth +2 : 0;
2
4048
by: Glen | last post by:
Hello, I've written a script in python and put together a simple QFrame with a QTextBrowser with Designer. I've translated the C++ into python using puic4. The .py file is called outputWin.py. My Script and its functions are in cnt.py. Finally, my main is in pball.py which follows here: import sys from PyQt4 import Qt, QtCore from outputWin import * from cnt import *
331
14977
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and most versatile text editor. And, besides text editing, it also serves as a
21
1853
by: globalrev | last post by:
i have a rough understanding of lambda but so far only have found use for it once(in tkinter when passing lambda as an argument i could circumvent some tricky stuff). what is the point of the following function? def addn(n): return lambda x,inc=n: x+inc if i do addn(5) it returns
97
2761
by: xahlee | last post by:
I'd like to introduce a blog post by Stephen Wolfram, on the design process of Mathematica. In particular, he touches on the importance of naming of functions. • Ten Thousand Hours of Design Reviews (2008 Jan 10) by Stephen Wolfram http://blog.wolfram.com/2008/01/10/ten-thousand-hours-of-design-reviews/ The issue is fitting here today, in our discussion of “closure” terminology recently, as well the jargons “lisp 1 vs lisp2”...
22
18151
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.