locked
code is nt working RRS feed

  • Question

  • public partial class customer
    {

        public void Add()
        {
            string str = "";
        }
        partial void validate();
        partial void parameter(int i);
    }

    public partial class customer
    {
        public void update()
        {
            validate();
            parameter(1);
        }
        partial void validate()
        {
            string str = "fsdf";
        }
        partial void parameter(int i)
        {

            string str = i.ToString();
        }
    }

    main (

       customer clst = new customer();
            clst.update();

    )

    Monday, September 18, 2017 1:19 PM

All replies

  •     public partial class customer
        {
    
            public void Add()
            {
                string str = "";
            }
            partial void validate();
            partial void parameter(int i);
        }
        public partial class customer
        {
               public void update()
                {
                    validate();
                    parameter(1);
                }
        }
        class Program
        {
            
            static void Main(string[] args)
            {
                 
              customer c =new customer();
              c.update();
            }
        }

    Hi mohit818 try this code 

    The partial methods cannot have mutliple declarations. 

    With a partial class you extend an existing class.  you don't have the declare validate and parameter method in the partial class

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods

    kind regards

    laurens


    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.




    Monday, September 18, 2017 1:54 PM
  • After fixing the syntax of Main function, the partial methods seem to work, i.e. the custom implementation of validate and parameter is executed. Give some details about the issue.

    Monday, September 18, 2017 5:32 PM
  • Hi Mohit818,

    Thank you for posting here.

    For the Main() method, you could refer to the following link for reference.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/

    If your question has been solved, please mark the useful reply as answer. This will make answer searching in the forum and be beneficial to community members as well.

    Best Regards,

    Wendy


    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.

    Wednesday, September 20, 2017 6:54 AM
  • Please merge this with this thread
    Wednesday, September 20, 2017 7:30 AM
    Answerer