Let us see how to make one or more parameters as optional in Web API.
public HttpResponseMessage GetDetails(String CompanyID, string VehicleType, string ModelNo)
Usually this method can be called like –
If we want to make VehicleType as optional and pass it as null value like below, it will throw an error.
This can be accomplished by moving all the optional parameters to last, assigning them a default value and passing them as separate values in the URL.
The method should be modified as –
public HttpResponseMessage GetDetails(String CompanyID, string ModelNo, string VehicleType = "ALL")
Then we can call the method as –
We can also add it to body as well.
You might have came across a situation where you set the default version of Visual Studio to some language mistakenly or you want to change it because of some reason. Here is the solution for it.
It might be looking silly. But for those who are in need. It mean a lot, I suppose.
There are two ways of doing this.
- Choose Tools -> Import and Export Settings…
- Select Reset All Settings and click Next
- Select whether you would like to save the current settings (I would say not here) and click Next
- Select the settings you want to use(change the language to C#) and click Finish
But, this is not advisable if there are any environmental settings that are set in the VS. In this case, you can use the following approach.
Modifying CurrentSettings.vssettings file. This file can be found in My DocumentsVisual Studio xSettings directory.
Open CurrentSettings.vssettings in a text or XML editor, and search for DefaultProjectLanguage.
You can then change the value accordingly. Here are the two options for VB or C#.
Save the file, and once you open Visual Studio, you’re set.
Hope this helps!