concept C # in category f#

This is an excerpt from Manning's book Get Programming with F#: A guide for .NET developers.
In some ways, we can think about F# as being the alternative side of the same coin from a C# perspective – often, things that are difficult to achieve in C# are easy to implement in F# - and vice versa. Let’s take a quick look at one example of that – creating mutable variables and immutable values in C# and F#.
Listing 0.1 Declaring values and variables in C# and F#
var name = "Isaac"; #1 const string name = "Isaac"; #2 let mutable name = "Isaac" #3 let name = "Isaac" #4 #1 Declaring a mutable variable in C# #2 Declaring an immutable value in C# #3 Declaring a mutable variable in F# #4 Declaring an immutable value in F#In C#, we normally use mutable variables by default to store data; to make them immutable, we need to use extra keywords (readonly, const etc.). Conversely in F#, to make mutable variables, we need to specify an extra mutable keyword, otherwise the language assumes you’re working with immutable data. This mentality applies across all of F# - it’s prescriptive about making it easy to work with certain language features that fit in with the functional programming style, whilst allowing us to revert to modelling problems with objects and imperative code if we’re willing to “pay the cost” of a few extra keywords. Here are some distinctions between the “default” ways of working across the three .NET languages; all of the features on the right-hand side can be considered conducive to writing code in the FP style.
Unless you’ve used only earlier versions of C#, you’ll almost certainly be familiar with the var keyword. Let’s refamiliarize ourselves with the var keyword based on the official MSDN documentation:
It’s important to stress that var mustn’t be confused with the dynamic keyword in C#, which is (as the name suggests) all about dynamic typing. var allows you to use static typing without the need to explicitly specify the type by allowing the compiler to determine the type for you at compile time (see figure 5.1).

This is an excerpt from Manning's book Real-World Functional Programming with Examples in F# and C#.
Listing 1.5. Creating a UI using the declarative and imperative styles (XAML and C#)
<!-- Declarative user interface in WPF and XAML --> <Canvas Background="Black"> <Ellipse x:Name="greenEllipse" Width="75" Height="75" Canvas.Left="0" Canvas.Top="0" Fill="LightGreen" /> </Canvas> // Imperative user interface using Windows Forms protected override void OnPaint(PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.Black, ClientRectangle); e.Graphics.FillEllipse(Brushes.LightGreen, 0, 0, 75, 75); }
The declarative description is represented as a treelike structure created from objects that represent individual GUI elements. It can be created in C#, but WPF also provides a more comfortable way using an XML-based language called XAML. Nevertheless, we’ll see that many similarities exist between XAML and LINQ. Listing 1.5 shows how the code in XAML compares with code that implements the same functionality using the imperative Windows Forms library.
Listing 1.5. Creating a UI using the declarative and imperative styles (XAML and C#)
<!-- Declarative user interface in WPF and XAML --> <Canvas Background="Black"> <Ellipse x:Name="greenEllipse" Width="75" Height="75" Canvas.Left="0" Canvas.Top="0" Fill="LightGreen" /> </Canvas> // Imperative user interface using Windows Forms protected override void OnPaint(PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.Black, ClientRectangle); e.Graphics.FillEllipse(Brushes.LightGreen, 0, 0, 75, 75); }
When we discussed tuples in chapter 3, we implemented a Tuple class in C# with the same behavior as F# tuples. Using tuples isn’t the normal way to return multiple values from a C# method, although you may still find it useful when writing C# code in a functional way. If you want to write this in C# without using tuples or declaring a new class for every method that returns multiple values, you’d probably use out parameters. You can see both approaches in listing 5.1, where we implement a simple function performing division with a remainder.
Explicit parameter typing is rarely needed in C#. You can’t use the var keyword to declare lambda functions anyway, so C# will usually be able to deduce the type. One exception is where we’re using the lambda function as an argument to a specific generic method. Even in F# we may occasionally need to give the compiler more information, which we do with type annotations. Listing 5.16 shows the lambda function with a type annotation to explicitly state the type of its parameter.