473,378 Members | 1,504 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,378 software developers and data experts.

'Repeat' pattern in C# for batch processing

Hello,

I was wondering if there is something equivalent to 'Repeat' pattern
in C# where I can say,

Repeat(10) myobj.SayHi();

The expansion of this being,

for (int i = 0; i < 10; ++i)
{
myObj.SayHi();
}

This is like a counted loop in assembly programming ...

Thanks,
WinCPP
Sep 22 '08 #1
5 2851
Well I think you just answered your question: use a loop.

RL

win_cpp wrote:
Hello,

I was wondering if there is something equivalent to 'Repeat' pattern
in C# where I can say,

Repeat(10) myobj.SayHi();

The expansion of this being,

for (int i = 0; i < 10; ++i)
{
myObj.SayHi();
}

This is like a counted loop in assembly programming ...

Thanks,
WinCPP
Sep 22 '08 #2
Dans son message précédent, win_cpp a écrit :
Hello,

I was wondering if there is something equivalent to 'Repeat' pattern
in C# where I can say,

Repeat(10) myobj.SayHi();

The expansion of this being,

for (int i = 0; i < 10; ++i)
{
myObj.SayHi();
}

This is like a counted loop in assembly programming ...

Thanks,
WinCPP
Hi WinCPP,

C# doesn't include this type of operator.
But you can create a utility method like that :

public static void Repeat(int number, Action action)
{
for (int i = 0; i < number; i++)
{
action();
}
}

And, when you are using it, it makes :

Repeat(10,() ={ myObj.SayHi(); });

--
Paul Musso
Sep 22 '08 #3
On Sep 22, 8:10*am, Paul Musso <pa...@exakis.comwrote:
Dans son message précédent, win_cpp a écrit :
Hello,
I was wondering if there is something equivalent to 'Repeat' pattern
in C# where I can say,
Repeat(10) myobj.SayHi();
The expansion of this being,
for (int i = 0; i < 10; ++i)
{
* * myObj.SayHi();
}
This is like a counted loop in assembly programming ...
Thanks,
WinCPP

Hi WinCPP,

C# doesn't include this type of operator.
But you can create a utility method like that :

public static void Repeat(int number, Action action)
{
* * for (int i = 0; i < number; i++)
* * {
* * * * action();
* * }

}

And, when you are using it, it makes :

Repeat(10,() ={ myObj.SayHi(); });

--
Paul Musso
thats a good abstraction... to make Repeat()

.....

-Cnu
Sep 22 '08 #4
Hi Paul,

Thanks for the suggestion. I try writing that.

As for using for loop, I was a bit lazy to type all the for (; ;)
stuff just to make a function call for 'known' number of times. So I
was looking for syntactic sugar which can reduce the burden of typing
and thus making the code less error prone.

At the language level, I was wondering if such an inbuilt
functionality would help in case of the loops for which the count is
known. As is evident from the usage, the 'Action' would be independent
of the induction variable for the loop. Compilers typically do
induction variable analysis and then perform loop inversions if it can
be established that the code *will* execute at least once. If there
were a construct such as 'Repeat' I guess it would consierably help
optimizations.

Regards,
WinCPP
http://www.linkedin.com/in/mandards

But you can create a utility method like that :
public static voidRepeat(int number, Action action)
{
* * for (int i = 0; i < number; i++)
* * {
* * * * action();
* * }
}
And, when you are using it, it makes :
Repeat(10,() ={ myObj.SayHi(); });
Sep 23 '08 #5
JS
As for using for loop, I was a bit lazy to type all the for (; ;)
stuff just to make a function call for 'known' number of times. So I
was looking for syntactic sugar which can reduce the burden of typing
and thus making the code less error prone.
Others who read your code will be very familiar with the for(;;)
statement, but it might confuse them to see some special looping
construct. In my opinion, you should stick with a for loop for
readability. Don't succumb to laziness at the expense of readability.
Sep 23 '08 #6

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

Similar topics

1
by: Christian Stork | last post by:
Hello everybody, I am using Python to prototype a compression algorithm for tree-shaped data, e.g., XML data or abstract syntax trees. I use a variant of the visitor design pattern--called...
2
by: Paul Reddin | last post by:
Hi, (V8.1 Fp2) Our application uses JDBC batch to execute mutiple insert statements and we saw a strange thing this morning. There were 4 SQL Insert statements in the batch, and we know the...
2
by: | last post by:
Hi, I have just started using MSSQL and the DOS environment at work. I have a lot of experience with Sybase and the UNIX environment, but this is a whole new ball of wax. I'd like to use osql...
1
by: Crash | last post by:
Hi, ..NET v1.x SP1 VS 2003 SQL Server 2000 SP3 Server 2000, XP, Server 2003 I would like to programmatically execute {possibly many} SQL Server batch scripts. Aka I have many scripts that...
4
by: acantatore | last post by:
Hello! I'm looking for patterns, best practices, examples - reference material - that apply to Batch Processing, that is: Basic job control (start and stop) Job partitioning Parallel...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
3
by: ludwig_stuyck | last post by:
Hi, does someone has some links to information about how I would approach and implement batch processing in C#? Thanks! Kind regards, Ludwig
6
by: Thomas Guettler | last post by:
Hi, I tried PIL for image batch processing. But somehow I don't like it - Font-Selection: You need to give the name of the font file. - Drawing on an image needs a different object that pasting...
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.