Small doubt in c# pls clarify me if any one

If we have passed three parameters into one method but i will call and pass Only two i wont call 3rd is it possible


6 Answers
1-6 of  6
6 Answers
  • Yes

  • You can set the last parameter as optional parameter.

  • You can use optional paramter
    public void test(int p1,int p2,int p3=0)
    {
    }
    call like this 
    test(1,2)
    if you want to pass value for 3rd paramter then 
    test(1,2,3)
     

  • No, It's not possible...you will get a compile-time error.
    If your question is: 
    method definition:
    public void input(int a, int b, int c)
    {
    }
    calling method:
    input(10,20);

    Thanks for A2A

  • public class Methodoveloading    
      {    
        public int add(int a, int b)  //two int type Parameters method  
        {    
            return a + b;    
            
        }    
        public int add(int a, int b,int c)  //three int type Parameters with same method same as above  
        {    
            return a + b+c;    
        
        }    
        public float add(float a, float b,float c,float d)  //four float type Parameters with same method same as above two method 

        {    
            return a + b+c+d;    
        
        }    
      }    

C Sharp Dot Net

Didn't get the answer.
Contact people of Talent-C Sharp Dot Net directly by clicking here