0% found this document useful (0 votes)
135 views21 pages

NET MAUI - Xamarin Interview Tips

The document states that the training data is current only until October 2023. This indicates that any events or developments occurring after this date are not included. Users should be aware of this limitation when seeking information.

Uploaded by

junior.cadastros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views21 pages

NET MAUI - Xamarin Interview Tips

The document states that the training data is current only until October 2023. This indicates that any events or developments occurring after this date are not included. Users should be aware of this limitation when seeking information.

Uploaded by

junior.cadastros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

.

NET MAUI/Xamarin Technical Interview Preparation Guide

Here are some commonly asked interview questions related


to .NET MAUI, C#, and Xamarin, along with answers:

1. What is .NET MAUI? How is it di6erent from Xamarin?

Answer:
.NET MAUI (Multi-platform App UI) is a cross-platform framework for
building native mobile and desktop applications with C# and XAML. It is the
evolution of Xamarin.Forms and enables a single codebase to target
Android, iOS, macOS, and Windows.
Key diMerences:

Single project structure in .NET MAUI, which simplifies multi-platform


development.

Native platform APIs and performance optimizations across all platforms.

MAUI supports desktop platforms (macOS and Windows), which


Xamarin.Forms did not fully support.

2. Explain the MVVM pattern and its role in .NET MAUI/Xamarin.

Answer:
The Model-View-ViewModel (MVVM) pattern is a design pattern used to
separate business logic from UI.

Model: Represents the data and business logic.

View: Represents the UI elements (pages, controls).


.NET MAUI/Xamarin Technical Interview Preparation Guide

ViewModel: Binds the Model to the View, handles UI logic and commands.

In .NET MAUI/Xamarin, MVVM enables the binding of UI elements (using


XAML) to data and commands in the ViewModel, making the codebase
more maintainable and testable.

3. What are Bindable Properties in Xamarin/.NET MAUI? How are they


created?

Answer:
A Bindable Property allows properties of controls to be bound to data
sources or other properties using data binding. They are used in custom
controls to enable binding to the control's properties.
To create a bindable property:

public static readonly BindableProperty ExampleProperty =


BindableProperty.Create(nameof(Example), typeof(string),
typeof(MyCustomControl), default(string));

public string Example


{
get => (string)GetValue(ExampleProperty);
set => SetValue(ExampleProperty, value);
}
.NET MAUI/Xamarin Technical Interview Preparation Guide

4. How can you navigate between pages in .NET MAUI or Xamarin?

Answer:
Navigation can be handled using the Navigation object in both Xamarin and
.NET MAUI. There are diMerent types of navigation:

Push/Pop Navigation:

await Navigation.PushAsync(new NextPage());


await Navigation.PopAsync();

Modal Navigation:

await Navigation.PushModalAsync(new ModalPage());


await Navigation.PopModalAsync();

Shell Navigation (in .NET MAUI):

await Shell.Current.GoToAsync("//HomePage");

5. How does dependency injection work in .NET MAUI?

Answer:
.NET MAUI has built-in support for dependency injection (DI), allowing
services to be injected directly into views, view models, and other
components.
To use DI in .NET MAUI:
.NET MAUI/Xamarin Technical Interview Preparation Guide

Register your services in MauiProgram.cs:

builder.Services.AddSingleton<IMyService, MyService>();

Inject services via the constructor in your view model:

public MyViewModel(IMyService myService)


{
_myService = myService;
}

6. What is Data Binding, and how does it work in .NET MAUI/Xamarin?

Answer:
Data Binding is the process of linking UI elements to data sources (like
ViewModels). In .NET MAUI/Xamarin, data binding connects the properties
of UI elements to data model properties using XAML or code-behind.
Example of binding in XAML:

<Label Text="{Binding Name}" />

In the ViewModel:

public string Name { get; set; }


.NET MAUI/Xamarin Technical Interview Preparation Guide

7. What is XAML, and how is it used in .NET MAUI/Xamarin?

Answer:
XAML (Extensible Application Markup Language) is a declarative language
used to define the UI of .NET MAUI/Xamarin applications. It separates the
design from the logic, allowing developers to define UI elements in XAML
and handle logic in the code-behind or ViewModel.

XAML example:

<StackLayout>
<Label Text="Welcome to .NET MAUI!" />
<Button Text="Click me" Command="{Binding MyCommand}" />
</StackLayout>

8. What are the di6erent layouts available in Xamarin/.NET MAUI?

Answer:
The commonly used layouts include:

StackLayout: Aligns child elements either vertically or horizontally.

Grid: Allows for creating a grid structure of rows and columns.

AbsoluteLayout: Positions elements absolutely relative to the parent.

FlexLayout: Provides flexibility in arranging child elements, similar to CSS


flexbox.
.NET MAUI/Xamarin Technical Interview Preparation Guide

ContentView and ScrollView: Wrappers that contain a single child view and
allow scrolling.

9. How do you handle platform-specific code in Xamarin/.NET MAUI?

Answer:
Platform-specific code can be written using conditional compilation or
platform-specific services:

Conditional Compilation:

#if ANDROID
// Android-specific code
#elif IOS
// iOS-specific code
#endif

Dependency Service or Dependency Injection for platform-specific


services in a shared project. Each platform will have its own
implementation, and the interface is shared across platforms.

10. What are Shell applications in .NET MAUI/Xamarin, and what are its
advantages?

Answer:
Shell provides a container for your application's UI, allowing simplified
navigation and layout.
.NET MAUI/Xamarin Technical Interview Preparation Guide

Advantages:

Simplified routing and navigation.

Flyout menus and tabs out-of-the-box.

Supports deep linking, URL-based navigation.

Example of a Shell file:

<Shell>
<FlyoutItem Title="Home">
<ShellContent ContentTemplate="{DataTemplate HomePage}" />
</FlyoutItem>
</Shell>

11. How does garbage collection work in C#?

Answer:
Garbage collection (GC) in C# is automatic memory management. The CLR
(Common Language Runtime) automatically releases unused memory by
collecting objects that are no longer referenced. The GC works in
generations to optimize memory usage: Generation 0, 1, and 2, with
objects promoted based on their longevity.
.NET MAUI/Xamarin Technical Interview Preparation Guide

12. Explain async and await in C#. How do they enhance application
performance?

Answer:
async and await are used to handle asynchronous programming in C#.
They allow for non-blocking code execution, which helps prevent UI
freezing or waiting for tasks to complete.
Example:

public async Task LoadDataAsync()


{
var data = await GetDataFromServerAsync();
// Process data
}

13. How do you handle background tasks in Xamarin/.NET MAUI?

Answer:
Background tasks in Xamarin/.NET MAUI can be handled using platform-
specific APIs:

iOS: Background Fetch, Background Transfer Service.

Android: WorkManager, Services.

Cross-Platform: Plugins like Shiny for background jobs.


.NET MAUI/Xamarin Technical Interview Preparation Guide

14. What are Value Converters, and how are they used?

Answer:
Value Converters in MVVM are used to convert data between the View and
the ViewModel. For example, you may convert a boolean property to a
string or color for display in the UI. Example of a simple converter:

public class BoolToColorConverter : IValueConverter


{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
return (bool)value ? Color.Green : Color.Red;
}}
Here are 30 commonly asked C# technical interview questions
with their answers:

1. What is C#?

Answer:
C# is a modern, object-oriented programming language developed by
Microsoft as part of its .NET initiative. It is designed for building
applications on the .NET framework, oMering features like garbage
collection, type safety, and exception handling.
.NET MAUI/Xamarin Technical Interview Preparation Guide

2. What are the main pillars of Object-Oriented Programming (OOP) in


C#?

Answer:
The four main pillars of OOP are:

Encapsulation: Bundling data and methods that operate on the data within
a single unit (class).

Abstraction: Hiding complexity by exposing only the necessary


functionality.

Inheritance: Allows one class to inherit properties and methods from


another class.

Polymorphism: Ability to take many forms; methods can perform diMerent


functions based on the object they are acting upon.

3. What is the di6erence between abstract class and interface?

Answer:

Abstract class: Can have method definitions and method implementations.


Allows multiple levels of inheritance and can include fields, properties, etc.
.NET MAUI/Xamarin Technical Interview Preparation Guide

Interface: Cannot have any implementations, only method signatures. A


class can implement multiple interfaces but can inherit from only one
abstract class.

4. What is a delegate in C#?

Answer:
A delegate is a type that defines a method signature and can point to
methods with a matching signature. It allows methods to be passed as
parameters, enabling callback mechanisms.

public delegate void MyDelegate(string message);

5. What are async and await in C#?

Answer:
async and await are used for asynchronous programming. They allow
methods to run asynchronously without blocking the calling thread. The
await keyword pauses the execution until the awaited task completes.

public async Task DoWorkAsync()


{
await Task.Delay(1000);
Console.WriteLine("Task Completed");
}
.NET MAUI/Xamarin Technical Interview Preparation Guide

6. What is a Nullable type in C#?

Answer:
A Nullable type allows value types (like int, bool) to have null values. This is
useful when dealing with databases or other external data sources that
allow null values.

int? nullableInt = null;

7. What are Lambda Expressions in C#?

Answer:
Lambda expressions are concise syntax for writing anonymous methods in
C#. They are often used in LINQ queries and functional programming.

Func<int, int> square = x => x * x;

8. What is the di6erence between ref and out parameters in C#?

Answer:

ref: The parameter must be initialized before being passed to the method.

out: The parameter does not need to be initialized before being passed, but
it must be assigned within the method.
.NET MAUI/Xamarin Technical Interview Preparation Guide

9. What is the di6erence between a struct and a class in C#?

Answer:

struct: Value type, stored on the stack, and is best for small, lightweight
objects.

class: Reference type, stored on the heap, and is used for more complex
objects.

10. What is a sealed class in C#?

Answer:
A sealed class cannot be inherited by any other class. This is useful when
you want to prevent other developers from deriving classes from your class.

11. What is a static class in C#?

Answer:
A static class cannot be instantiated and can contain only static members
(methods, fields, etc.). It is used when a class is meant to provide
functionality without the need for object instances.
.NET MAUI/Xamarin Technical Interview Preparation Guide

12. What is the IS and AS keyword in C#?

Answer:

is: Used to check if an object is of a particular type.

if (obj is string) { ... }

as: Used to safely cast an object to a type. Returns null if the cast fails.

string s = obj as string;

13. What is the di6erence between finalize and dispose in C#?

Answer:

Finalize: Automatically called by the garbage collector to clean up


unmanaged resources. Cannot be called directly.

Dispose: Manually called by the developer to release unmanaged


resources. Implemented through the IDisposable interface.
.NET MAUI/Xamarin Technical Interview Preparation Guide

14. What is the di6erence between const and readonly?

Answer:

const: Must be assigned at compile time and cannot be changed.

readonly: Can be assigned at runtime in the constructor and cannot be


modified after assignment.

15. What is LINQ in C#?

Answer:
LINQ (Language Integrated Query) allows querying of data from diMerent
data sources (arrays, collections, databases) in a concise and readable
way. LINQ queries can be written using query syntax or method syntax.

16. What is boxing and unboxing in C#?

Answer:

Boxing: Converting a value type to an object type.

int x = 10;
object obj = x; // boxing

Unboxing: Extracting the value type from an object.

int y = (int)obj; // unboxing


.NET MAUI/Xamarin Technical Interview Preparation Guide

17. What is a foreach loop in C#?

Answer:
A foreach loop is used to iterate over a collection or array. It automatically
handles iterating through each element in the collection.

foreach (var item in collection)


{
Console.WriteLine(item);
}

18. What is yield in C#?

Answer:
yield is used in iterator methods to return each value one at a time. It allows
creating custom iterators without the need for explicit state management.

public IEnumerable<int> GetNumbers()


{
yield return 1;
yield return 2;
}

19. What is an enum in C#?

Answer:
An enum is a distinct type that consists of named constants. It is often
used for representing a set of related values.
.NET MAUI/Xamarin Technical Interview Preparation Guide

enum Days { Sunday, Monday, Tuesday }

20. What is the lock keyword in C#?

Answer:
The lock keyword ensures that a block of code runs by only one thread at a
time. It is used to handle synchronization in multi-threaded environments.

lock (lockObject)
{
// critical section
}

21. What is the di6erence between IEnumerable and IQueryable?

Answer:

IEnumerable: Executes the query in-memory, suitable for in-memory


collections.

IQueryable: Executes the query on the server-side (deferred execution),


suitable for querying databases.
.NET MAUI/Xamarin Technical Interview Preparation Guide

22. What is SOLID in C#?

Answer:
SOLID is a set of five principles for designing maintainable and scalable
software:
S: Single Responsibility Principle

O: Open/Closed Principle

L: Liskov Substitution Principle

I: Interface Segregation Principle

D: Dependency Inversion Principle

23. What is Dependency Injection (DI) in C#?

Answer:
Dependency Injection is a design pattern used to achieve loose coupling. It
allows objects to be injected with their dependencies at runtime rather
than creating them internally.

24. What are Partial Classes in C#?

Answer:
Partial classes allow a class to be split into multiple files. It’s useful when a
class is too large or generated by a tool (e.g., designer files in Visual
Studio).
.NET MAUI/Xamarin Technical Interview Preparation Guide

25. What is Exception Handling in C#?

Answer:
Exception handling allows a program to deal with unexpected errors. It
uses try, catch, finally, and throw blocks to handle and propagate
exceptions.

try
{
// code that may throw an exception
}
catch (Exception ex)
{
// handle exception
}
finally
{
// cleanup code
}

26. What is a Task in C#?

Answer:
A Task represents an asynchronous operation in C#. Tasks can run
asynchronously, making it easier to manage background operations like file
I/O, database access, etc.
.NET MAUI/Xamarin Technical Interview Preparation Guide

27. What is the di6erence between Task and Thread?

Answer:

Task: Represents a single operation that does not return a value and can be
awaited. It is part of the System.Threading.Tasks namespace and provides
higher-level abstractions for parallelism and asynchronous operations.

Thread: A lower-level abstraction used for running code in parallel. Threads


are heavier than tasks and require manual management (like creation,
synchronization, and disposal).

// Example of using Task


Task.Run(() => DoWork());
// Example of using Thread
Thread thread = new Thread(DoWork);
thread.Start();

28. What is the di6erence between Array and ArrayList in C#?

Answer:

Array: Fixed size and type-safe (only elements of a specified type can be
stored).

ArrayList: Can dynamically resize and store elements of diMerent types. It is


not type-safe and uses object internally. For type safety, prefer List<T> over
ArrayList.
.NET MAUI/Xamarin Technical Interview Preparation Guide

int[] numbers = new int[3]; // Array


ArrayList list = new ArrayList(); // ArrayList

29. What is the var keyword in C#?

Answer:
The var keyword is used for implicit type declaration. The compiler infers
the type of the variable based on the value assigned. It must be initialized
at the time of declaration.

var number = 10; // inferred as int


var name = "John"; // inferred as string

30. What is Entity Framework in C#?

Answer:
Entity Framework (EF) is an ORM (Object-Relational Mapper) that simplifies
data access by allowing developers to work with databases using C#
objects. It eliminates the need for most SQL queries by generating queries
at runtime based on LINQ.

using (var context = new MyDbContext())


{
var users = context.Users.ToList(); // Query using LINQ
}

You might also like