none
enum class for error handling RRS feed

  • Question

  • Hello,

    Please let me know how could I use the parameters of an enum class in another class.

    public enum ErrClass
        {

            ERROR_CODE = "FAILED",
            RFQ_ERROR_DESC = "DB CONNECTION FAILURE",
            RFQ_REASON_CODE = 101,

        }

    We would like to call the ERROR_CODE from the error class and return the "FAILED" message to the mail class

    Please suggest how to proceed.Thanks in advance!!

    Saturday, November 8, 2014 6:45 PM

Answers

  • An enum must be a numeric value.  So the numeric value can be a enumeration

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                B.ErrClass error = B.errors.AsEnumerable()
                    .Where(x => x.ERROR_NUM == B.ERROR_ENUM.RFQ_REASON_CODE).Single();
            }
        }
    
        public class B
        {
            public enum ERROR_ENUM
            {
               RFQ_REASON_CODE = 101
            }
            static public List<ErrClass> errors = new List<ErrClass>(){
                new ErrClass(){ERROR_CODE = "FAILED", RFQ_ERROR_DESC = "DB CONNECTION FAILURE", ERROR_NUM = ERROR_ENUM.RFQ_REASON_CODE}
            };
            public class ErrClass
            {
    
                public string ERROR_CODE { get; set; }
                public string RFQ_ERROR_DESC { get; set; }
                public ERROR_ENUM ERROR_NUM { get; set; }
    
            }
        }
    }
    


    jdweng

    Sunday, November 9, 2014 8:06 AM

All replies

  • Try something like this

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                B.ErrClass error = B.errors.AsEnumerable()
                    .Where(x => x.RFQ_REASON_CODE == 101).Single();
            }
        }
    
        public class B
        {
            static public List<ErrClass> errors = new List<ErrClass>(){
                new ErrClass(){ERROR_CODE = "FAILED", RFQ_ERROR_DESC = "DB CONNECTION FAILURE", RFQ_REASON_CODE = 101}
            };
            public class ErrClass
            {
    
                public string ERROR_CODE {get; set;}
                public string RFQ_ERROR_DESC {get; set;}
                public int RFQ_REASON_CODE {get; set;}
    
            } 
        }
    }
    


    jdweng

    Sunday, November 9, 2014 1:03 AM
  • Hi ,

    Thank you !!

    We have been asked to write an enum class for the error handling .Please let me know if it is possible to write it with enum class.

    Thanks and Regards

    Sunday, November 9, 2014 3:52 AM
  • An enum must be a numeric value.  So the numeric value can be a enumeration

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                B.ErrClass error = B.errors.AsEnumerable()
                    .Where(x => x.ERROR_NUM == B.ERROR_ENUM.RFQ_REASON_CODE).Single();
            }
        }
    
        public class B
        {
            public enum ERROR_ENUM
            {
               RFQ_REASON_CODE = 101
            }
            static public List<ErrClass> errors = new List<ErrClass>(){
                new ErrClass(){ERROR_CODE = "FAILED", RFQ_ERROR_DESC = "DB CONNECTION FAILURE", ERROR_NUM = ERROR_ENUM.RFQ_REASON_CODE}
            };
            public class ErrClass
            {
    
                public string ERROR_CODE { get; set; }
                public string RFQ_ERROR_DESC { get; set; }
                public ERROR_ENUM ERROR_NUM { get; set; }
    
            }
        }
    }
    


    jdweng

    Sunday, November 9, 2014 8:06 AM