コード例 #1
0
ファイル: Program.cs プロジェクト: angloyna/csharp_work
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var john = new Person();

            john.firstName = "John";
            john.lastName  = "Smith";
            john.Introduce();
            Calculator calc   = new Calculator();
            var        result = calc.Add(1, 2);

            System.Console.WriteLine(result);

            var numbers = new int[3];

            numbers[0] = 1;
            System.Console.WriteLine(numbers[0]);
            System.Console.WriteLine(numbers[1]);
            System.Console.WriteLine(numbers[2]);

            var flags = new bool[3];

            flags[0] = true;

            var names = new string[3] {
                "Jack", "John", "Mary"
            };

            string list = string.Join(", ", numbers);

            System.Console.WriteLine(list);

            var formattedNames = string.Join(",", names);

            System.Console.WriteLine(formattedNames);

            var text = @"Hi John
Look into the following
c:\folder1";

            System.Console.WriteLine(text);

            var method = ShippingMethod.Express;

            System.Console.WriteLine((int)method);

            var methodId = 3;

            System.Console.WriteLine((ShippingMethod)methodId);

            System.Console.WriteLine(method);

            var methodName = "Express";

            var shippingMethod = (ShippingMethod)System.Enum.Parse(typeof(ShippingMethod), methodName);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GeniusAlg0s/C-practice
        static void Main(string[] args)
        {
            Person pat = new Person();

            pat.FirstName = "pat";
            pat.LastName  = "will";
            pat.Introduce();

            Calculator calculator = new Calculator();
            var        result     = calculator.Add(1, 2);

            Console.WriteLine(result);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var person = new Person(new DateTime(1982, 2, 6));

            System.Console.WriteLine(person.Age);
            person.Name = "Angela";
            person.Introduce("Mosh");

            var otherPerson = Person.Parse(new DateTime(1992, 7, 23), "Peter");

            otherPerson.Introduce("Mosh");

            var customer = new Customer(1, "John");

            System.Console.WriteLine(customer.Id);
            System.Console.WriteLine(customer.Name);
            var order = new Order();

            customer.Orders.Add(order);
            foreach (var ord in customer.Orders)
            {
                System.Console.WriteLine("order: " + ord);
            }

            var otherCustomer = new Customer
            {
                Id   = 45,
                Name = "Angela Gloyna"
            };

            System.Console.WriteLine(otherCustomer.Name);

            System.Console.WriteLine(Calculator.Add(new int[] { 4, 5, 6, 9 }));
            System.Console.WriteLine(Calculator.Add(1, 2, 4, 5));
            try
            {
                var point = new Point(10, 20);
                point.Move(new Point(40, 60));
                System.Console.WriteLine("x: {0}, y: {1}", point.X, point.Y);

                point.Move(100, 200);
                System.Console.WriteLine("x: {0}, y: {1}", point.X, point.Y);
            } catch (Exception)
            {
                System.Console.WriteLine("An unexpected error occurred.");
            }
        }