Hi my name is Darryl, I'm from the beautiful island of Trinidad (in the caribbean). I'm also new to your forum and very excited about understanding and becoming better at C#.
Thank you. Have a great day.
Oh one question. I have seen in other tutorials that {0} is used instead of +. What's the difference?
Thank you. Have a great day.
Oh one question. I have seen in other tutorials that {0} is used instead of +. What's the difference?
Hi Darryl and welcome to the site.
The {0} notation is usually used within string formatting, like this:
It could be written with string concatenation as well, but some people prefer using the Format function, and it is a bit cleaner in some situations imo
The {0} notation is usually used within string formatting, like this:
Console.WriteLine(String.Format("Hello {0} {1}", firstName, lastName);
It could be written with string concatenation as well, but some people prefer using the Format function, and it is a bit cleaner in some situations imo

Thanks for the info. Much appreciated.
Hi I have another question:
when I run the following program I am getting the output of the first element of the array to be 49. I am expecting to see '1' as defined in the array, if n = 0.
What am I doing wrong?
using System;
namespace Array1
{
class ArrayVariable
{
static int Main()
{
int[] Array1 = { '1', '2', '3' };
Console.WriteLine("Enter a value for n?");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("n:{0} ", n );
Console.WriteLine("the value of the nth array is: {0}", Array1 [n] );
Console.ReadLine();
return 0;
}
}
}
when I run the following program I am getting the output of the first element of the array to be 49. I am expecting to see '1' as defined in the array, if n = 0.
What am I doing wrong?
using System;
namespace Array1
{
class ArrayVariable
{
static int Main()
{
int[] Array1 = { '1', '2', '3' };
Console.WriteLine("Enter a value for n?");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("n:{0} ", n );
Console.WriteLine("the value of the nth array is: {0}", Array1 [n] );
Console.ReadLine();
return 0;
}
}
}
Hi Darryl,
Hehe funny problem actually. You define an array of ints, but actually, you put chars into it. Normally, the compiler would complain about stuff like that, but in this case, a char can be mapped directly to an integer, and if you look at a table of ASCII character codes, you will see that the number 1 has position 49. Change your line so that you put actual numbers in the array and it should work just fine:
int[] Array1 = { 1, 2, 3 };

Hehe funny problem actually. You define an array of ints, but actually, you put chars into it. Normally, the compiler would complain about stuff like that, but in this case, a char can be mapped directly to an integer, and if you look at a table of ASCII character codes, you will see that the number 1 has position 49. Change your line so that you put actual numbers in the array and it should work just fine:
int[] Array1 = { 1, 2, 3 };

Thank you very much. I'm still learning...
I'm happy to hear that. Just post again if you have other questions 

Hi, I hope you can help with a files.directories proble.
I am looking for a way to print the files in a file array at once, so they all print as one job and show as one print job on the print spooler. If its even possible.
Thanks.
Kay
I am looking for a way to print the files in a file array at once, so they all print as one job and show as one print job on the print spooler. If its even possible.
Thanks.
Kay
Hello All,
I'm also new in C# and so far I understand most of the topics pretty clear I have to say. My problem is with the chapter "Static" in specific, I am doing the practical exer. :
public class Rectangle
{
private int width, height;
public Rectangle(int width, int height)
{
this.width = width;
this.height = height;
}
public void OutputArea()
{
Console.WriteLine("Area output: " + Rectangle.CalculateArea(this.width, this.height));
}
public static int CalculateArea(int width, int height)
{
return width * height;
}
}
And when I call the class Rectangle (inside static void Main()) and I give the parameters like this Rectagle.CalculateArea(5,5) The compiler is working but nothing is displayed. Maybe I am doing something wrong in here.
Could you please advise me ?
Thanks in advance!
I'm also new in C# and so far I understand most of the topics pretty clear I have to say. My problem is with the chapter "Static" in specific, I am doing the practical exer. :
public class Rectangle
{
private int width, height;
public Rectangle(int width, int height)
{
this.width = width;
this.height = height;
}
public void OutputArea()
{
Console.WriteLine("Area output: " + Rectangle.CalculateArea(this.width, this.height));
}
public static int CalculateArea(int width, int height)
{
return width * height;
}
}
And when I call the class Rectangle (inside static void Main()) and I give the parameters like this Rectagle.CalculateArea(5,5) The compiler is working but nothing is displayed. Maybe I am doing something wrong in here.
Could you please advise me ?
Thanks in advance!
Dear Brother AOA,
your code is correct but u not call the OutputArea() fuction.. you can write in main like following then its work....
static void Main(string[] args)
{
Rectangle rec = new Rectangle(5,5);
rec.OutputArea(); // this display your value
Console.ReadKey();
}
your code is correct but u not call the OutputArea() fuction.. you can write in main like following then its work....
static void Main(string[] args)
{
Rectangle rec = new Rectangle(5,5);
rec.OutputArea(); // this display your value
Console.ReadKey();
}
© net-tutorials.com 2006 - 2010