Hello,
I am parsing some main arguments and calling to functions according to
it. Is it possible not to define the called functions as static? How can
I design it better?
Thanks
*** Sent via Developersdex http://www.developersdex.com *** 8 4050
You can create a helper class containing those methods, then
instantiate the helper class in the main() method, e.g.
public class Program {
public static void Main(string[] args) {
ArgumentHandler handler = new ArgumentHandler (args);
}
}
public class ArgumentHandler {
public ArgumentHandler (string[] args) {
ProcessArgs(arg s);
}
private void ProcessArgs(str ing[] args) {
// do something with the command-line arguments
}
}
csharpula csharp wrote:
Hello,
I am parsing some main arguments and calling to functions according to
it. Is it possible not to define the called functions as static? How can
I design it better?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Hi csharpula,
why do you think, the function shouldn't be static. Your post is very
unclear about, what you want to acomplish. Maybe a static method is simply
the best solution in your case.
"csharpula csharp" <cs*******@yaho o.comschrieb im Newsbeitrag
news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
Hello,
I am parsing some main arguments and calling to functions according to
it. Is it possible not to define the called functions as static? How can
I design it better?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Main is a static function, so the function called by Main should be
statis. It's very clear.
Christof Nordiek wrote:
Hi csharpula,
why do you think, the function shouldn't be static. Your post is very
unclear about, what you want to acomplish. Maybe a static method is simply
the best solution in your case.
"csharpula csharp" <cs*******@yaho o.comschrieb im Newsbeitrag
news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
Hello,
I am parsing some main arguments and calling to functions according to
it. Is it possible not to define the called functions as static? How can
I design it better?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Hooyoo <zh*********@12 6.comwrote:
Main is a static function, so the function called by Main should be
statis. It's very clear.
Not really - it's perfectly possible to call non-static methods from
Main; you just need to create an instance of something on which to call
the instance method. For example:
using System;
class Counter
{
int limit;
Counter (int limit)
{
this.limit = limit;
}
void Start()
{
for (int i=0; i < limit; i++)
{
Console.WriteLi ne (i);
}
}
static void Main(string[] args)
{
Counter counter = new Counter(int.Par se(args[0]));
counter.Start() ;
}
}
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aha, I knew that. I mean Main call some functions not some methods of
a object, that is the question.
Jon wrote:
Hooyoo <zh*********@12 6.comwrote:
Main is a static function, so the function called by Main should be
statis. It's very clear.
Not really - it's perfectly possible to call non-static methods from
Main; you just need to create an instance of something on which to call
the instance method. For example:
using System;
class Counter
{
int limit;
Counter (int limit)
{
this.limit = limit;
}
void Start()
{
for (int i=0; i < limit; i++)
{
Console.WriteLi ne (i);
}
}
static void Main(string[] args)
{
Counter counter = new Counter(int.Par se(args[0]));
counter.Start() ;
}
}
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hooyoo <zh*********@12 6.comwrote:
Aha, I knew that. I mean Main call some functions not some methods of
a object, that is the question.
Well, I had assumed that "function" was being used as a synonym for
"method" seeing as Main is a static *method* and there's no such thing
as a "function" in C#.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
You misunderstood me, see the following snippet:
using System;
class Counter
{
int limit;
Counter (int limit)
{
this.limit = limit;
}
void Start()
{
for (int i=0; i < limit; i++)
{
Console.WriteLi ne (i);
}
}
static void Main(string[] args)
{
/*Start menthod is non-static method, so you cannot write like
this:
Start();
so some smart guys will write like this right way:
*/
Counter counter = new Counter(int.Par se(args[0]));
counter.Start() ; //You cannot call
//* Like passing "this" pointer to static member functions in
c++
}
}
Jon wrote:
Hooyoo <zh*********@12 6.comwrote:
Aha, I knew that. I mean Main call some functions not some methods of
a object, that is the question.
Well, I had assumed that "function" was being used as a synonym for
"method" seeing as Main is a static *method* and there's no such thing
as a "function" in C#.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On 30 Nov 2006 01:15:24 -0800, "Hooyoo" <zh*********@12 6.comwrote:
>You misunderstood me, see the following snippet: using System;
{snip}
Despite what you say, Jon is correct. There are no "functions" in C#. Only
methods.
>Well, I had assumed that "function" was being used as a synonym for "method" seeing as Main is a static *method* and there's no such thing as a "function" in C#.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Good luck with your project,
Otis Mukinfus http://www.arltex.com http://www.tomchilders.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jean-Francois Brault |
last post by:
I wrote a crappy class for radian angle management. The class consists
of an array of radian values. I put all these things in a class in
which all methods are static, so I can access it anywhere in my code
(I could have made a library instead of a class).
I can't find out why g++ compiles fine, but does not link correctly
the following code. Here, I am posting my full code, .h and .cpp just
to make all things clear.
The linker output...
|
by: Dumitru Sipos |
last post by:
Hello everybody!
is there possible to have a function that is both static and virtual?
Dumi.
|
by: Samee Zahur |
last post by:
Question: How do friend functions and static member functions differ in
terms of functionality? I mean, neither necessarily needs an object of
the class to be created before they are called and either has access
only to static members of the class (ie. assuming no object of the
class is in scope - neither by arguments recieved nor by local
declarations). Any static member function like this:
//accessing static member i
static void...
|
by: Tony Johansson |
last post by:
Hello experts!
Why is not possible to have virtual static members
Many thnakn
//Tony
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you experts.
I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of
ways to do this through prototyping and other techniques, but these
behaviors need to be static and...
| |
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in C# in some
way? Or maybe no, because it is similar to a global variable (with its
scope restricted) which C# is dead against?
Zytan
|
by: lcdgoncalves |
last post by:
Hi everyone
Is there a real need to use keyword static with functions, if we
simply don't declare their prototypes in .h file?
Many textbooks avoid to discuss this matter and/or discuss only the
usage of static functions. I've been programming for years and I never
felt a real need for the "static approach for functions".
I don't know if this is a trivial matter since the reserved word
|
by: Sandro Bosio |
last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long.
I'm trying to achieve the following (with incomplete succes): I want in a given namespace Parameters a list of "initializers" (which are objects derived from a simple interface that can be implemented anywhere, and are used to define which parameters the program will take at...
|
by: Jess |
last post by:
Hello,
I learned that there are five kinds of static objects, namely
1. global objects
2. object defined in namespace scope
3. object declared static instead classes
4. objects declared static inside functions (i.e. local static
objects)
5. objects declared at file scope.
|
by: Pramod |
last post by:
Hello to all of you,
I want to know that what's the use to create static object.
Thanks You
Pramod Sahgal
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 project—planning, coding, testing, and deployment—without 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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |