コード例 #1
0
ファイル: Program.cs プロジェクト: sharifazhar168/azhar
        static void Main(string[] args)
        {
            var Thomas = new Person();

            Thomas.firstName = " Thomas";
            Thomas.lastName  = " Newt";
            Thomas.Introduce();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Anu-Tomy/csharp-intro
        static void Main(string[] args)
        {
            var john = new Person();

            john.FirstName = "John";
            john.LastName  = "Smith";
            john.Introduce();
        }
コード例 #3
0
        private static void ObjectExample()
        {
            // Object example
            Person mark = new Person();

            mark.FirstName = "Mark";
            mark.LastName  = "Bradshaw";
            mark.Introduce();
        }
コード例 #4
0
        static void PersonInitializer()
        {
            Person person = new Person
            {
                FirstName = "John",
                LastName  = "Smith"
            };

            person.Introduce();
        }
コード例 #5
0
ファイル: someClassThings.cs プロジェクト: schan1992/box
        static void Main(string[] args)
        {
            Person john = new Person();
            john.FirstName = "John";
            john.LastName = "Smith";
            john.Introduce();

            Calculator calculator = new Calculator();
            int result = calculator.Add(1, 2);
            Console.WriteLine(result);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var nafissa = new Person();

            nafissa.FirstName = "Nafissa";
            nafissa.LastName  = "Hassan";
            nafissa.Introduce();
            Calculator caclulator = new Calculator();
            var        result     = caclulator.Add(1, 2);

            Console.WriteLine(result);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: ladevl/csharpfundamentals
        static void Main(string[] args)
        {
            var john = new Person();

            john.FirstName = "John";
            john.LastName  = "Smith";
            john.Introduce();

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

            Console.WriteLine(result);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: jslineses/ATM
        static void Main(string[] args)
        {
            var george = new Person();

            george.FirstName = "George";
            george.LastName  = "Naismith";
            george.Introduce();

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

            Console.WriteLine(result);
        }
コード例 #9
0
        public static Main(string[] args)
        {
            var hugo = new Person();

            hugo.FirstName = "Hugo";
            hugo.LastName  = "James";
            hugo.Introduce();

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

            System.Console.WriteLine(result);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            var josh = new Person();

            josh.FirstName = "Josh";
            josh.LastName  = "Bristol";
            josh.Introduce();

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

            Console.WriteLine(result);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: MACTEP-ETF/C-Sharp
        static void Main(string[] args)
        {
            var Vladimirs = new Person();

            Vladimirs.FirstName = "Vladimirs";
            Vladimirs.LastName  = "Fedorovics";
            Vladimirs.Introduce();

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

            System.Console.WriteLine(result);
        }
コード例 #12
0
        public static void Do()
        {
            var type = (int)CustomerType.Bronze;

            Console.WriteLine(type);

            Console.WriteLine("Hello World!");

            Person person = new Person();

            person.FirstName = "Anant";
            person.LastName  = "Sharma";

            person.Introduce();
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: hungvxforthewin/csharp
        static void Main(string[] args)
        {
            var a = new Person();

            a.firstName = "Mosh";
            a.lastName  = "Hamedani";
            a.Introduce();


            var b      = new Calcurator();
            var result = b.Add(4, 5);

            Console.WriteLine(result);

            Console.WriteLine(CalcuratorStatic.Add(1, 4));

            int    i = 1234;
            string s = i + "";
        }
コード例 #14
0
        static void Main(string[] args)
        {
            var John = new Person();

            John.FirstName = "John";
            John.LastName  = "Smith";
            John.Introduce();

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

            Console.WriteLine(result);

            var numbers = new int[3];

            numbers[0] = 1;

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

            var flags = new bool[3];

            flags[0] = true;

            Console.WriteLine(flags[0]);
            Console.WriteLine(flags[1]);
            Console.WriteLine(flags[2]);

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

            Console.WriteLine(names[0]);
            Console.WriteLine(names[1]);
            Console.WriteLine(names[2]);
            Console.WriteLine(names[0]);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: violentr/cSharp_playground
        static void Main(string[] args)
        {
            var p = new Person();

            p.firstName = "John";
            p.lastName  = "Smith";
            p.Introduce();

            /* Array */
            var numbers = new int[3];

            numbers[0] = 1;
            numbers[1] = 2;
            Console.WriteLine("{0} {1}", numbers[0], numbers[1]);
            Console.WriteLine(numbers[2]); //not initialized -> defaults to 0

            var flags = new bool[3];

            flags[0] = true;

            Console.WriteLine(flags[0]);
            Console.WriteLine(flags[1]); //not initialized -> defaults to false
            var names = new string[3] {
                "Jack", "James", "Jany"
            };

            Console.WriteLine("Name: ", names[1]);
            //Console.WriteLine(names[3]);// will raise an exception

            /* Enum */
            var methodName = "Express";
            var s          = (MyEnums.ShippingMethod)Enum.Parse(typeof(MyEnums.ShippingMethod), methodName);

            Console.WriteLine("shippingMethod id is {0}", (int)s);

            /* control flow */
            var season = MyEnums.Season.Winter;

            MyEnums.chooseSeason(season);
            var hour = 10;

            if (hour > 0 && hour < 12)
            {
                Console.WriteLine("Good Morning");
            }
            else if (hour > 12 && hour < 18)
            {
                Console.WriteLine("Good afternoon");
            }
            else
            {
                Console.WriteLine("Good evening");
            }

            /* Loops */
            const int count = 7;
            var       list  = new int[count] {
                1, 2, 3, 4, 5, 6, 7
            };

            Utilities.myForLoop(list);
            Utilities.myForEachLoop(list);
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: rathoddharmendra/Lab
        public static void Main(string[] args)
        {
            var coder = new Person();

            coder.FirstName = "Dharmendra";
            coder.LastName  = "Rathod";

            coder.Introduce();

            //

            Calculator data   = new Calculator();
            var        result = data.sum(29, 31);

            System.Console.WriteLine(result);;


            //

            var numbers = new int[5] {
                1, 2, 3, 5, 6
            };

            numbers[1] = 10;

            System.Console.WriteLine(numbers[1]);


            var flags = new bool[3];

            flags[0] = true;

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

            var names = new string[3];

            System.Console.WriteLine(names[0]);

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

            System.Console.WriteLine(list);
            String name = "Dharmendra Rathod";

            Int32 i;

            var someNames = new string[3] {
                "Ass", "Kicker", "LoL"
            };

            var joinedNames = string.Join("||", someNames);

            Console.WriteLine(joinedNames);

            // verbatim string:
            var text = @"Hi Dear,
  Kindly look into below path:
   C:\Users\rathod\Desktop\sample.db";

            Console.WriteLine(text);
        }
コード例 #17
0
        static void Main(string[] args)
        {
            // Beeps
            {
                Console.Beep(500, 200);
                Console.Beep(500, 200);
            }

            // Person
            var jj = new Person();

            jj.FirstName = "JJ";
            jj.LastName  = "Jameson";
            jj.Introduce(); // Hello, my name is JJ Jameson

            // Calculator
            Calculator calculator = new Calculator();
            var        result     = calculator.Add(5, 7);

            Console.WriteLine(result); // 12

            // Arrays
            var numbers = new int[3];

            numbers[0] = 1;

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

            var flags = new bool[3];

            flags[0] = true;

            Console.WriteLine(flags[0]); // True
            Console.WriteLine(flags[1]); // False
            Console.WriteLine(flags[2]); // False

            // Strings
            // string, var, and String all produce the same result
            string firstName  = "The";
            var    middleName = "Big";
            String lastName   = "Lebowski";

            Console.WriteLine($"{firstName} {middleName} {lastName}"); // The Big Lebowski

            var fullName = string.Format("My name is {0} {1} {2}", firstName, middleName, lastName);

            Console.WriteLine(fullName); // My name is The Big Lebowski

            var names = new string[3] {
                "Liam", "Owen", "Jameson"
            };
            var formattedNames = string.Join(',', names);

            Console.WriteLine(formattedNames); // Liam,Owen,Jameson

            // Enums
            var method = ShippingMethod.Express;

            Console.WriteLine((int)method);  // 3

            var methodId = 3;

            Console.WriteLine((ShippingMethod)methodId); // Express
            Console.WriteLine(method.ToString());        // Express

            var methodName = "Express";

            var shippingMethod = (ShippingMethod)Enum.Parse(typeof(ShippingMethod), methodName);

            Console.WriteLine(shippingMethod); // Express
        }
コード例 #18
0
        static void Main(string[] args)
        {
            /////////////////////////////

            var john = new Person();

            john.FirstName = "John";
            john.LastName  = "Smith";
            john.Introduce();

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

            // Because the cw method is defined as static, you do not have to create a new Console instance(object) of Console class
            // to call the cw method
            Console.WriteLine(result);

            /////////////////////////////

            // create an array. numbers is an identifier
            var numbers = new int[3];

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

            // boolean array
            var flags = new bool[3];

            flags[0] = true;
            Console.WriteLine(flags[0]);
            Console.WriteLine(flags[1]);
            Console.WriteLine(flags[2]);

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

            Console.WriteLine(names[0]);
            Console.WriteLine(names[1]);
            Console.WriteLine(names[2]);

            /////////////////////////////

            // String which is a class on the system namespace. primiive types e.g. int are srucures.
            var firstName = "Mosh";
            var lastName  = "Hamedani";

            var fullName = firstName + " " + lastName;

            // format is a static method of string class
            // Statis methods arw accessible without a need to create an object
            var myFullName = string.Format("My name is {0} {1}", firstName, lastName);

            // .Join is also a static method on the string class
            var namesTwo = new string[3] {
                "John", "Jack", "Mary"
            };
            var formattedNames = string.Join(", ", namesTwo); // separator, array

            Console.WriteLine(formattedNames);

            var text = "Hi John \nLook into the following paths \nc:\\folder1\\folder2\nc:\\folder3\\folder4";

            Console.WriteLine(text);

            var text2 = @"Hi John
Look into the following paths
c:\folder1\folder2
c:\folder3\folder3";

            Console.WriteLine(text2);

            /////////////////////////////

            var method = ShippingMethod.Express;

            Console.WriteLine(((int)method)); //casting

            var methodId = 3;                 // we want to convert this to ShippingMethod using casting

            Console.WriteLine((ShippingMethod)methodId);


            Console.WriteLine(method.ToString());

            // string to enum
            var methodName = "Express";
            //parsing converts string to a different type
            var shippingMethod = (ShippingMethod)Enum.Parse(typeof(ShippingMethod), methodName);

            /////////////////////////////

            var a = 10;
            var b = a;

            b++; //icrement operator

            //integeres are value types (values are coppied. a and b are independent)
            Console.WriteLine(string.Format("a: {0}, b: {1}", a, b));

            // array is reference type (the memory address is the same)
            var array1 = new int[3] {
                1, 2, 3
            };
            var array2 = array1;

            array2[0] = 0;

            Console.WriteLine(string.Format("array1: {0}, array2: {1}", array1[0], array2[0])); //Both are zero

            /////////////////////////////

            // Value type
            var number = 1;            // this is inside the scope of main method. It does not have meaning outside

            Increment(number);         // because int is a value type, the number is still 1. number inside the Increment has a different place in memory
            Console.WriteLine(number); // 1

            // Ref type sharing the seme reference (memory) in the heap
            var person = new PersonTwo()
            {
                Age = 20
            };

            MakeOld(person);
            Console.WriteLine(person.Age);
        }