Showing posts with label Interactive C#. Show all posts
Showing posts with label Interactive C#. Show all posts

Monday, July 23, 2018

Can I run a Class Library project in an interactive session?

A Class Library project creates a class file, a .dll. You cannot run it directly because there is no executable, lacks a Main() program.

However, you can run it in an interactive session by following the next mentioned steps:

Right click the Class Library Project and choose Initialize Interactive from the drop-down list:



ClassLibFrameInteractive_0

The C# Interactive session begins with loading the project context related files as shown.


ClassLibFrameInteractive_00

Now that Joinstring namespace creates a class, Create an instance of the class as cls1.

cls1 can now access the Add method in Class1 which takes two arguments.
Supply them and print the result as shown.


ClassLibFrameInteractive
-------------
Here is the Joinstring project folder and Class1.cs



ClassLibFrameInteractive_000


ClassLibFrameInteractive_001

Tuesday, March 27, 2018

How do you convert Integer to Boolean in C#?


Start Interactive C# in Visual Studio Community 2017. Here are examples of integers (+ and -) and 0 converted to Boolean, using the Convert.ToBoolean(). This functions has 8 overloads.

Read here about running C# in interactive mode.

> bool p = Convert.ToBoolean(6);
> p
true
> bool k = Convert.ToBoolean(0);
> k
false
> bool q = Convert.ToBoolean(-8);
> q
true