Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Square each number in an array, without using loops.

Aug
2,799
144
Requires TCC Version 36.00.24 x64 or later.

I've added example 9 to template.csx,
which demonstrates how to square each number in an array,
without using loops.

Code:
// Example 9: Square each number in an array,
//   without using loops.
// Example input array
int[] numbers = { 1, 2, 3, 4, 5 };
                                               
// Square each number without explicit loops
int[] squaredNumbers = numbers
.Select(n9 => checked(n9 * n9)) // checked to detect overflow
.ToArray();
// Display results
Console.WriteLine("Original: " + string.Join(", ", numbers));
Console.WriteLine("Squared: " + string.Join(", ", squaredNumbers));

Attached please find the latest version of the CsScript plugin,
and the template.csx file.

Code:
R:\>plugin /l csscript.dll

R:\>plugin /i csscript
Module:      csscript.dll
Name:        CsScript
Author:      Joe Caverly
Email:       [email protected]
Web:         https://github.com/joec4281?tab=repositories
Description: CsScript command to run CSharp code
Implements:  CSSCRIPT
Version:     2026.4  Build 10

R:\>csscript template.csx
No arguments provided.

Today's Date: 2026-04-11
Current Time: 14:17:33

Circle with radius 5: Area = 78.54
Is 121 a palindrome?
Yes
Three

TCC PShell get-date: April 11, 2026 2:17:33 PM
TCC PShell 2026-1960: 66
Original: 1, 2, 3, 4, 5
Squared: 1, 4, 9, 16, 25


R:\>

Joe
 

Attachments

I've added the ARRAY2 command to the CsScript plugin (attached).

From the command line;
Code:
U:\>array2 2026 04 12
4104676 16 144

Code:
U:\>array2 0 1 2 4 8 16 32 64 128 256
0 1 4 16 64 256 1024 4096 16384 65536

This uses LINQ to square each number,
without the need for loops.

Joe
 

Attachments

Back
Top