954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

setw() function in C#?

Hi, I'd like to have tabs in my console app, but instead of using \t, I'd like to use an equivalent of the C++ setw() method in C#. Any ideas of what I might use?

And another thing, in C++, you would declare more than one array with indexes like this:

int x[10], y[10], z[10];

Is there a shorter way than writing like this in C# :

int[] x = new int[10];
int[] y = new int[10];
int[] z = new int[10];

Thanx for the help, if someone knows.

Edit: Oh, damnit, wrong forum! Can a mod move it to the C# forum?

silkfire
Newbie Poster
8 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Hey there silkfire,

On the array question, do you need three distinct arrays? You could create a multidimensional array, like a jagged array:

int [][][] njaggedArray = new int [10][10][10];

Will that work?

EricaJanine
Newbie Poster
22 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

nah, wood like to separate the arrays, but thanx anyway =)

silkfire
Newbie Poster
8 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 
int[] x = y = z = new int[10];
// or I THINK this works too
int[] x, y, z = new int[10];
Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 46
Solved Threads: 2
 

setw() equiv would be sth like this:

String.Format("{0,10:D}", 2) : will format number 2 as a string of width 10 aligned to the right, use -10 to have it aligned on the left

as for declaring the vars, you can do it like this:

int[] a, b, c = new int[10];

r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 13
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You