Click here to Skip to main content
15,566,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below mentioned code is of a single dimensional array code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace array_demo
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            //int[] arr = new int []{ 1, 2, 3, 4 };
            //int[] arr = { 1, 2, 3, 4 };
            int[] arr = new int[3];
            arr[0] = (5);

            textBox1.Text = Convert.ToString(arr[0],arr[1],arr[2]);

now here if i am giving only a single arr value i.e. if type


the above lime displays me an out put as 5 in textbox. now if i try to put in 2 more arguments for ToString it obviously throws an error ' No overload for method "ToString" takes 3 arguments.

Now is it advisable to overload Tostring to accomidate n number of arguments or any specific method(leaving for lop etc)
mpvkrishnadhar 16-Apr-12 2:34am    
sorry for the typos!

you can concatenate the array values and then convert, otherwise tostring accepts only one parameter and that cannot be altered..

you can do something like this

textbox1.text=convert.tostring(arr[0] + arr[1] + arr[2]);

hope this helps..
have a grt day!!
Share this answer
mpvkrishnadhar 16-Apr-12 2:52am    
hi bro!

doesn't the statement textbox1.text=convert.tostring(arr[0]+arr[1]+arr[2}); add all the values of the 3 array indexes and gives me a value of 35
Roliking 16-Apr-12 3:11am    
or else u can do something like this..

textBox1.Text = arr[0].ToString() + arr[1].ToString() + arr[2].ToString();
this will work perfectly fine!!
mpvkrishnadhar 16-Apr-12 3:15am    
perfect bro! got the solution! thanks a lot!
I suggest go for a new method something like this:

public string toString(int[] x)
        string r = "";
        foreach (int i in x)
            r = r + "," + i.ToString();
        return r;

r = r + "," + i.ToString();
according to ur output

I don't suggest overload because this is very long way for u to do a small task.

I hope this will help u.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900