473,382 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

non-class methods

I know I sound like a dolt for asking, but if I have a few functions that
any objects in my code can call, mostly these are functions, how do I make
them public to the application? I'm confused about whether or not I put
them in a class or not a class. I know in VB there is an object called a
module which just holds "unstructured" or as I see it free-for-all code.

thanks
Nov 16 '05 #1
8 1264
Keith,

You want to make them public static. This will allow any code that can
see the type (which is any code in an assembly that references the assembly
where the type that has this method is contained) to execute it without an
instance (the static part).

A module in VB really compiles to a class with static methods.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Keith Henderson" <kh********@projectresources.nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I know I sound like a dolt for asking, but if I have a few functions that
any objects in my code can call, mostly these are functions, how do I make
them public to the application? I'm confused about whether or not I put
them in a class or not a class. I know in VB there is an object called a
module which just holds "unstructured" or as I see it free-for-all code.

thanks

Nov 16 '05 #2
Hi, Keith.
You don't have much of a choice in C#. :) In C#, functions are either
defined in a class, or a struct (a value type). If you want to call the
functions from any where and the functions don't require any instance data,
you can put them into a public class as static member functions. VB.NET
modules are also eventually mapped to .NET CLR classes.

Ming Chen

"Keith Henderson" <kh********@projectresources.nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I know I sound like a dolt for asking, but if I have a few functions that
any objects in my code can call, mostly these are functions, how do I make
them public to the application? I'm confused about whether or not I put
them in a class or not a class. I know in VB there is an object called a
module which just holds "unstructured" or as I see it free-for-all code.

thanks

Nov 16 '05 #3
hi Keith

the following code is doing what you want.
make an abstract class so nobody can make instances from it!
make every method in this class static so you dont have to instance an
object of this class for using its methods.

--- CODE ---
public abstract class MyFunctions
{
public static void func1()
{
}
public static int func2(string something)
{
MyFunctions.func1();
}
}

cheers, jazper
Nov 16 '05 #4
If you want to stop people instantiating the class this is only going to sort of work

public class Foo : MyFunctions

{

}

MyFunctions f = new Foo();

this will construct your class when the derived one constructs.

To stop anyone constructing just create a provate default constructor

public class MyFunctions

{

private MyFunctions(){}

...

}

In Whidbey we get the concept of a static class from which teh compiler emits a sealed abstract class.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#s**************@TK2MSFTNGP11.phx.gbl>

hi Keith

the following code is doing what you want.
make an abstract class so nobody can make instances from it!
make every method in this class static so you dont have to instance an
object of this class for using its methods.

--- CODE ---
public abstract class MyFunctions
{
public static void func1()
{
}
public static int func2(string something)
{
MyFunctions.func1();
}
}

cheers, jazper

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #5
Thanks group.

I also looked in my data access application block and saw that it started
with

public sealed class _classname_
{
public static _datatype_ _methodname_
{
...
}
}

so sealed can also stop the class from being instantiated. is this right?

Richard Blewett [DevelopMentor] wrote:
If you want to stop people instantiating the class this is only going
to sort of work

public class Foo : MyFunctions

{

}

MyFunctions f = new Foo();

this will construct your class when the derived one constructs.

To stop anyone constructing just create a provate default constructor

public class MyFunctions

{

private MyFunctions(){}

...

}

In Whidbey we get the concept of a static class from which teh
compiler emits a sealed abstract class.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#s**************@TK2MSFTNGP11.phx.gbl>

hi Keith

the following code is doing what you want.
make an abstract class so nobody can make instances from it!
make every method in this class static so you dont have to instance an
object of this class for using its methods.

--- CODE ---
public abstract class MyFunctions
{
public static void func1()
{
}
public static int func2(string something)
{
MyFunctions.func1();
}
}

cheers, jazper

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

[microsoft.public.dotnet.languages.csharp]

Nov 16 '05 #6
Keith Henderson <kh********@projectresources.nospam.com> wrote:
Thanks group.

I also looked in my data access application block and saw that it started
with

public sealed class _classname_
{
public static _datatype_ _methodname_
{
...
}
}

so sealed can also stop the class from being instantiated. is this right?


No. Sealed just means it can't be derived from. String is a sealed
class, for instance - but you can still instantiate it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
GOT IT!

Jon Skeet [C# MVP] wrote:
Keith Henderson <kh********@projectresources.nospam.com> wrote:
Thanks group.

I also looked in my data access application block and saw that it
started with

public sealed class _classname_
{
public static _datatype_ _methodname_
{
...
}
}

so sealed can also stop the class from being instantiated. is this
right?


No. Sealed just means it can't be derived from. String is a sealed
class, for instance - but you can still instantiate it.

Nov 16 '05 #8
Add a module in the project and create your methods within the module.
This will make your methods globally acessible throughout the project.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
4
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.