Can we have vb.net / F#.net class files in C#.NET project…?

No, You can not mix vb and c# within the same project,but you can use them in the same solution. An assembly/project (each project compiles to 1 assembly usually) has to be one language. However, you can use multiple assemblies, and each can be coded in a different language because they are all compiled to MSIL.

You can add vb.net files to a c#.net project. Compilation also works. It compiles fine and didn’t complain because a  C# project will only actually compile the .cs files. It will ignore the other ones, therefore you will not receive errors.

Note: If you add a .vb file to a C# project, select the file in the Solution Explorer panel and then look at the Properties panel, you’ll notice that the Build Action is ‘Content’, not ‘Compile’. It is treated as a simple text file and doesn’t even get embedded in the compiled assembly as a binary resource.

Advertisements

Intro: Web Api in MVC4

The Web Api (Application Programming Interface) feature is based on a special kind of controller to an MVC framework application.

An api controller distinguishes itself from the normal controllers by the following :-

  • Action methods return model, rather than an ActionResult in MVC, objects.
  • Action methods are selected based on the HTTP method used in the request.

The model objects that are returned from an API controller action method are encoded as JSON/XML based on the browsers used and sent to the client.

 

By Sriramjithendra Posted in WebAPI

Splitting Datatable in C#.Net

var totalRows = myDatatable.Rows.Count;
var halfway = totalRows/2;
var firstHalf = myDatatable.AsEnumerable().Take(halfway).CopyToDataTable();
var secondHalf = myDatatable.AsEnumerable().Skip(halfway).Take(totalRows – halfway).CopyToDataTable();

By Sriramjithendra Posted in C#.NET

Checking Web.config contains a specific key

if(ConfigurationManager.AppSettings.AllKeys.Contains("specificKey"))
{
// the config file contains the specific key 
 }

but if you only want to check the value

var specificValue =ConfigurationManager.AppSettings["specificKey"];
if(!string.IsNullOrEmpty(specificValue))
{
// Use the value
}