Пример #1
0
        public static DateTimeOffset AskForDateOfBirth()
        {
            Console.WriteLine($"Can I start by asking you " +
                              $"what your date of birth is? { CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern }");

            var someString  = "Some string";
            var someString2 = "Some " + "string";
            var someString3 = 4.ToString();
            var someString4 = $"I earned { 400 } today";

            var todaysDate    = DateTimeOffset.UtcNow;
            var todaysWeather = SomeWeatherProvider.GetWeatherToday();
            var rainfall      = RainfallData.HeightInInches;

            var someString5 = $"Today is { todaysDate }" +
                              $" and the weather outside is { todaysWeather }" +
                              $". The rainfall is expected to be { rainfall } inches.";

            //var someInvalidString = $"{ Console.WriteLine() }";

            var someResult  = 1 * 4;
            var someString6 = $"{ someResult }";

            var userText = Console.ReadLine();

            return(DateTimeOffset.Parse(userText));
        }
Пример #2
0
        public static DateTimeOffset AskForDateOfBirth()
        {
            Console.WriteLine($"Can I start by asking you " +
                              $"what your date of birth is? { CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern }");

            var someString  = "Some string";
            var someString2 = "Some " + "string";
            var someInt     = 4;
            var someString3 = "Some string " + someInt;
            var someString4 = "I earned " + 400.ToString() + " today";
            var someString5 = $"I earned { 400 } today";

            // First version of the string
            var someText = "Today is " + DateTimeOffset.UtcNow.ToString() +
                           "and the weather outside is " +
                           SomeWeatherProvider.GetWeathertoday().ToString() +
                           ". The rainfall is expected to be " +
                           RainfallData.HeightInInches.ToString() + " inches.";

            // Second version of the string with interpolation
            var someText2 = $"Today is { DateTimeOffset.UtcNow } " +
                            $"and the weather outside is { SomeWeatherProvider.GetWeathertoday() } " +
                            $". The rainfall is expected to be { RainfallData.HeightInInches } inches.";

            // Third version of the string
            var todaysDate    = DateTimeOffset.UtcNow;
            var todaysWeather = SomeWeatherProvider.GetWeathertoday();
            var rainfall      = RainfallData.HeightInInches;

            var someText3 = $"Today is { todaysDate } " +
                            $"and the weather outside is { todaysWeather } " +
                            $". The rainfall is expected to be { rainfall } inches.";


            var someInvalidString = $" { Console.WriteLine() }";

            var userText = Console.ReadLine();

            return(DateTimeOffset.Parse(userText));
        }