473,408 Members | 2,477 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,408 software developers and data experts.

C# params constructor

Hello

The script I have below does what I've been asked :

Write a method that accepts an array of numbers as a parameter. The method should multiply each number by ten, and display the results. Call this method, passing to it an array of any three integers.

What I'd like to know is if this is correct or if there is a better way to do this?

Expand|Select|Wrap|Line Numbers
  1.  using System;
  2.  class Array
  3.  {
  4.      int int1;
  5.      int int2;
  6.      int int3;
  7.  
  8.      public Array(params int[] numbers)
  9.      {
  10.          int1    =    numbers[0];
  11.          int2    =    numbers[1];
  12.          int3    =    numbers[2];
  13.  
  14.  
  15.          Console.WriteLine("Number 1: " + (int1 * 10));
  16.          Console.WriteLine("Number 2: " + (int2 * 10));
  17.          Console.WriteLine("Number 3: " + (int3 * 10));
  18.  
  19.      }            
  20.  
  21.  }
  22.  
  23.  public class ArrayNumbers
  24.  {
  25.      public static void Main()
  26.      {
  27.          Array myArray = new Array(23, 2, 10);
  28.      }
  29.  }
Thanks

M
Mar 7 '08 #1
1 3133
Plater
7,872 Expert 4TB
That is a much more complex method then I think you would need.
A simple function that takes in an int[] as an argument seems like it would be fine.


We do not do homework assignments here, so you will have to look up how to use an int[] yourself. (Pretty basic, there should be plenty of examples online)
Mar 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ondrej Sevecek | last post by:
This returns exception about constructor not found: Object inputParameters = new Object { this, tabControl }; System.Runtime.Remoting.ObjectHandle objectHandle =...
0
by: Mihaly | last post by:
Hello, i'm using a VC++ com+ object, it's reference in vs .net, this com object have a function that have to params, the interop com object recive Object Params and the original com object say...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
0
by: Efkas | last post by:
I am trying some interresting features to load an assembly on the fly. I read some samples, but what I am trying to do is a little more complex. - First, I have a app.config file containing keys...
3
by: Stan Huff | last post by:
Is there any way to disable the "params" on a particular invocation so that one can pass an array containing the arguments and not have receiver get an array having you argument array stuffed into...
8
by: David Duerrenmatt | last post by:
Hi there For some reasons, I've to use Python 1.5.2 and am looking for a workaround: In newer Python versions, I can call a function this way: func = some_function func(*params) Then,...
3
by: lavu | last post by:
How would I pass parameters from the main form to my subform at load time. I use Activator.CreateInstance to create the subform. Thanks in advance. Ps: I tried googling for this but found no...
2
by: FFMG | last post by:
Hi, I was looking at http://www.php.net/manual/en/function.call-user-func-array.php and I was wondering... Given, // -- function foo( &$params) {
9
by: =?Utf-8?B?UElFQkFMRA==?= | last post by:
Given a method like void F ( params object args ) { ... } I had always _assumed_ that args would never be null, but now it's been brought to my attention that if the caller uses F ( null )...
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...
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

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.