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 5 2881
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
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
On Sep 22, 8:10*am, Paul Musso <pa...@exakis.c omwrote:
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
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(); });
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 weaver/yarn pattern--in order to
traverse the tree that is being compressed or decompressed. I do not
know of any other interesting application of the weaver/yarn pattern,
but it seems like a very suitable subject of study for different...
|
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 2nd
would have
violated a Unique Constraint and failed, but the SQL error returned
was related to the 3rd statement (which had a FK dependent on the 2nd
|
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 from a batch file to log into the dataserver and
run a fairly long list of SQL and then exit. I don't want to have a bunch
of SQL files sitting around that I have to use the -i option to run, and
I'd rather not create temporary SQL files like...
|
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 drop/add stored procedure
definitions, alter table definitions & constraints, etc... and I would
|
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 processing and distribution
Fine-grained transaction control
Error handling
| |
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
Me.txtEmail.SetFocus
Exit Sub
End If
Me.txtStatusBar.Value = "Parsing..."
strEmail = Me.txtEmail.Value
|
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 screen appearance of the Select
List grows for the first 5 rows then the scroll bar appears if there's
more). So far so good. . .
The problem is that none of the rows I'm inserting appear on the screen
until I have RETURNed from my function; so If...
|
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
|
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 and saving.
- The handbook is from Dec. 2006.
What image libraries do you suggest?
I think there are these alternatives:
|
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: 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...
|
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: 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...
| |