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 4039
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(args);
}
private void ProcessArgs(string[] 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*******@yahoo.comschrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP02.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*******@yahoo.comschrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP02.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*********@126.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.WriteLine (i);
}
}
static void Main(string[] args)
{
Counter counter = new Counter(int.Parse(args[0]));
counter.Start();
}
}
--
Jon Skeet - <sk***@pobox.com> 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*********@126.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.WriteLine (i);
}
}
static void Main(string[] args)
{
Counter counter = new Counter(int.Parse(args[0]));
counter.Start();
}
}
--
Jon Skeet - <sk***@pobox.com> 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*********@126.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.com> 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.WriteLine (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.Parse(args[0]));
counter.Start(); //You cannot call
//* Like passing "this" pointer to static member functions in
c++
}
}
Jon wrote:
Hooyoo <zh*********@126.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.com> 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*********@126.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.com> 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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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: 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,...
|
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...
|
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...
|
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,...
| |