using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
(new Program()).run();
}
public void run() {
double dailyRate = readDouble("Enter your daily rate: ");
int noOfDays = readInt("Enter the number of days: ");
writeFee(calculateFee(dailyRate, noOfDays));
}
private void writeFee(double p) {
Console.WriteLine("The consultant's fee is: {0}", p * 1.1);
}
private double calculateFee(double dailyRate, int noOfDays) {
return dailyRate * noOfDays;
}
private int readInt(string p) {
Console.Write(p);
string line = Console.ReadLine();
return int.Parse(line);
}
private double readDouble(string p) {
Console.Write(p);
string line = Console.ReadLine();
return double.Parse(line);
}
}
Software Development
software development notes, main category for Cs, Java, and other programming experiences.
illustrates how to read command-line arguments
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example10_4.cs illustrates how to read
command-line arguments
*/
using System;
public class Example10_4
{
public static void Main(string[] arguments)
{
for (int counter = 0; counter < arguments.Length; counter++) { Console.WriteLine("arguments[" + counter + "] = " + arguments[counter]); } } } [/csharp]
Program argument input values: Converts degrees Celsius to degrees Fahrenheit
using System;
public class PassArguments {
public static void Main(String[] args) {
double hotC, coldC;
double hotF, coldF;
if (args.Length != 2) {
Console.WriteLine ("Enter a hot and a cold temerature as program arguments.");
return;
}
hotC = double.Parse(args[0]);
hotF = 9.0*hotC/5.0 + 32.0;
Console.WriteLine ("The Fahrenheit temperature is: {0:F1}", hotF);
coldC = double.Parse(args[1]);
coldF = 9.0*coldC/5.0 + 32.0;
Console.WriteLine ("The Fahrenheit temperature is: {0:F1}", coldF);
}
}
To Four Digit Year
using System;
using System.Globalization;
class Class1
{
static void Main(string[] args)
{
Calendar MyCalendar = new GregorianCalendar();
Console.WriteLine(MyCalendar.ToFourDigitYear(32));
Console.WriteLine(MyCalendar.ToFourDigitYear(28));
}
}
Two Digit Year Max
using System;
using System.Globalization;
class Class1
{
static void Main(string[] args)
{
Calendar MyCalendar = new GregorianCalendar();
CultureInfo MyCulture = new CultureInfo("es-ES");
DateTime MyDate = new DateTime(2006,8,22,15,30,0,0);
Console.WriteLine(MyCalendar.TwoDigitYearMax);
}
}
ToString(): make it culture aware
using System;
using System.Globalization;
class Class1
{
static void Main(string[] args)
{
Calendar MyCalendar = new GregorianCalendar();
CultureInfo MyCulture = new CultureInfo("es-ES");
DateTime MyDate = new DateTime(2006,8,22,15,30,0,0);
Console.WriteLine(MyCalendar.AddMinutes(MyDate, 15).
ToString("G",
MyCulture));
}
}
Calendar ToDateTime is not culture aware
using System;
using System.Globalization;
class Class1
{
static void Main(string[] args)
{
Calendar MyCalendar = new GregorianCalendar();
CultureInfo MyCulture = new CultureInfo("es-ES");
DateTime MyDate = new DateTime(2006,8,22,15,30,0,0);
//
Console.WriteLine(MyCalendar.ToDateTime(MyDate.Year,
MyDate.Month,
MyDate.Day,
MyDate.Hour,
MyDate.Minute, 0, 0));
}
}