Photography web hosting - CHAPTER 3 76 C# LANGUAGE FUNDAMENTALS Figure
CHAPTER 3 76 C# LANGUAGE FUNDAMENTALS Figure 3-7. String format flags in action Console.WriteLine(”N format: {0:N}”, 99999); Console.WriteLine(”X format: {0:X}”, 99999); Console.WriteLine(”x format: {0:x}”, 99999); } Be aware that the use of .NET formatting characters is not limited to console applications. These same flags can be used within the context of the static String.Format() method. This can be helpful when you need to build a string containing numerical values in memory for use in any application type (Windows Forms, ASP.NET, XML web services, and so on): static void Main(string[] args) { … // Use the static String.Format() method to build a new string. string formatStr; formatStr = String.Format(”Don’t you wish you had {0:C} in your account?”, 99989.987); Console.WriteLine(formatStr); } Figure 3-7 shows a test run. Source Code The BasicConsoleIO project is located under the Chapter 3 subdirectory. Establishing Member Visibility Before we go much further, it is important to address the topic of member visibility. Members (methods, fields, constructors, and so on) of a given class or structure must specify their visibility level. If you define a member without specifying an accessibility keyword, it automatically defaults to private. C# offers the method access modifiers shown in Table 3-4.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.