Code sharing is one of the key concepts when developing applications with Xamarin. In this section, we will learn how to use the available options of sharing code between platforms when creating a Xamarin solution, Shared Project and Portable Class Library, and what the key differences are.
We will start with creating a solution based in Shared Project.
Start Visual Studio. In the top menu, select File | New | Project… and in the Templates | Mobile Apps tab choose Blank App (Xamarin.Forms Shared). Name it
XamFormsSharedProject
, choose your directory path, and click OK.With that, you get four projects: the
XamoFormsSharedProject
core shared project and the corresponding Android, iOS, and Windows Phone platform projects.Create a new class in the core
XamFormsSharedProject
project, right-click, Add | Class…, and give it the nameNameService.cs
. Make it public.