none
There is no given argument given that corresponds to the required formal parameters RRS feed

  • Question

  • Hi All,

    I am an error as mentioned in title when I tried to call the method from one class to another. I will copy my code here. 

    Class1:

    public class Class1
    {
    public void GetInfo()
    
    {
    
    // Code here
    
    }
    }


    This method is used in the Class1. Now I want to use this method in another class called Class2. So I have created an object in Class2 for Class1 class and tried to call the method.

    Class2:
    
    Class1() obj = new Class1();
    
    obj.GetInfo();


    On building the project, I am getting the above error.

    Please help.


     


    Wednesday, December 20, 2017 6:37 AM

Answers

  • object is a reserved word in c# and has a special meaning and you are also missing braces at the end of Class1, a quick fix if you want to use it as variable name would be like:

    Class1 @object = new Class1();
    
    @object.GetDoc();

    prepending @ would make it a legal variable.

    Hope it helps!


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites





    Wednesday, December 20, 2017 9:09 AM
  • The object is not a valid variable name, new Class1 should include parentheses, and there is no GetDoc in Class1.

    If possible, give more details about the real code, show the erroneous line, and check if right number of arguments are passed.



    Wednesday, December 20, 2017 7:42 AM

All replies

  • The object is not a valid variable name, new Class1 should include parentheses, and there is no GetDoc in Class1.

    If possible, give more details about the real code, show the erroneous line, and check if right number of arguments are passed.



    Wednesday, December 20, 2017 7:42 AM
  • object is a reserved word in c# and has a special meaning and you are also missing braces at the end of Class1, a quick fix if you want to use it as variable name would be like:

    Class1 @object = new Class1();
    
    @object.GetDoc();

    prepending @ would make it a legal variable.

    Hope it helps!


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites





    Wednesday, December 20, 2017 9:09 AM
  • Remove the parens from the type name. 

    Class1 obj = new Class1();
    obj.GetInfo();

    The error you're posting is a little vague and doesn't line up with the code you posted. You have edited the code since the others have posted without providing any info. Please do not alter your original post in response to other posts as we lose context. Reply with the updated code so we can see the transition.

    At this point we'll need to see the code you have now along with line # information from the compiler.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 20, 2017 2:43 PM
    Moderator
  • Hi Karthik Veerabathiran,

    According to your description, I create a simple demo, it throw an exception, but it different with you, the solution is as CoolDadTx said, Remove the brackets from the type name. 

    I would suggest that you could provide a complete code about Class1 and Class2, it will be beneficial to resolve the issue.

    Best regards,

    Zhanglong Wu


    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.

    Thursday, December 21, 2017 6:35 AM
    Moderator