none
Expression Evaluation RRS feed

  • Question

  • Hi

    Is there any way to create function or expression that evaluate the dynamic express. 

    Like my requirement is I need to pass the string and its process and return string.


    string.Format("{0} Q{1}", DateTime.Now.Year.ToString(), ((DateTime.Now.AddMonths(+3).Month + 2) / 3).ToString())

    Thanks

    • Edited by Inayat72 Monday, June 17, 2019 7:02 PM
    Monday, June 17, 2019 6:57 PM

All replies

  • Hi Inayat72,

    Thank you for posting here.

    Based on your description, you want to create a function or expression that evaluate the dynamic express.

    You could try the following code.

     public static string Evaluate(DateTime time)
            {
                return string.Format("{0} Q {1}", time.Year.ToString(), ((time.AddMonths(+3).Month + 2) / 3).ToString());
            }
     static void Main(string[] args)
            {
                DateTime time = DateTime.Now;
                string result = Evaluate(time);
                Console.WriteLine(result);
                Console.ReadKey();
            }

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 18, 2019 3:10 AM
    Moderator