Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In my application while creating derived class object baseclass constructor called and dervied class constructor also called at the time varibles are intalized and then operations are performed on the method.finally return the response.in that response i had get varibles are get with values based on operation performed and default values initialization don't want return the default value initialization. i need varibles are initialized with values based operation performed.
C#
[HttpPost]
[Route("api/Account/Login")]
 public async Task<GetBaseCustomerResponse> Login([FromBody]LoginRequest request)
  {
  GetBaseCustomerResponse _response = new GetBaseCustomerResponse();


   -----operations are performed--------



   return _response 
}


C#
public class GetBaseCustomerResponse : GetResponseTemplate<BaseCustomerModel>
{
      
}


C#
public class BaseCustomerModel
{
public int Customerid{get;set;}

public string cusname{get;set;}

public string cusaddress{get;set;}

public string email{get;set;}

public string Dateofbirth{get;set;}

}


please help me.
Thank u

What I have tried:

In my application while creating derived class object baseclass constructor called and dervied class constructor also called at the time varibles are intalized and then operations are performed on the method.finally return the response.in that response i had get varibles are get with values based on operation performed and default values initialization don't want return the default value initialization. i need varibles are initialized with values based operation performed
Posted
Updated 2-Feb-19 18:18pm
Comments
M.Kamran Asim 25-Nov-18 23:43pm    
Can you elaborate more. your requirements are confusing. Please if you can share source code, expected input and response.
As I understand you only need data which you had fill during operation, but you are receiving default values of other properties. For example in your BaseCustomerModel you dont want customerId, but you are receiving 0 value in response object, where 0 is meaningful to you.

This is default behavior of CLR, that it will initialize object with default value, but still if you dont need default value of int, double, float etc, make it nullable and ignore nullable in response.
Krishna Veni 25-Nov-18 23:49pm    
Yes.i don't want default value initialization while return
[no name] 25-Nov-18 23:57pm    
In the above code, where did you set default value?

1 solution

You can set the properties in the call to new:
C#
new GetBaseCustomerResponse { Property1 = value1, Property2 = value2 ...};

Without more information on what you are trying to do or sample code, it is hard to offer much more advice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900