|
|
Types with the same names from different namespaces
/csbook/solutions/13/A01.cs
namespace Util {
enum Color {Red, Blue, Green}
}
namespace MyJob {
using System;
using System.Drawing;
class Test {
// This method gets a predefined name of a System.Drawing.Color and
// sets the value of Util.Color such that it corresponds to the
// highest R, B or G component of the input color.
// Call it like:
// ns Orange
public static void Main(string[] arg) {
if (arg.Length == 0) {
Console.WriteLine("specify a color as an argument");
} else {
Color c = Color.FromName(arg[0]);
if (c.IsKnownColor) {
Util.Color color;
if (c.R > c.B)
if (c.R > c.G) color = Util.Color.Red;
else color = Util.Color.Green;
else // c.B >= c.R
if (c.B > c.G) color = Util.Color.Blue;
else color = Util.Color.Green;
Console.WriteLine("R={0}, B={1}, G={2} ==> {3}", c.R, c.B, c.G, color);
} else {
Console.WriteLine(arg[0] + " is not a known color");
}
}
}
}
}
|
|