TweetFollow Us on Twitter

Up and Running with the SSCLI

Volume Number: 19 (2003)
Issue Number: 11
Column Tag: Programming

Casting your .NET

Up and Running with the SSCLI

by Andrew Troelsen

Exploring .NET development on Mac OS X

Let there be code

In the last issue, you were introduced to a number of specifications that qualify the .NET platform, collectively termed the Common Language Infrastructure (CLI). As mentioned, these specs (no matter how detailed) do us little good until they are implemented in a usable code base. In this installment, you will obtain, configure and explore one such implementation of the CLI named the Shared Source CLI (SSCLI). Although the SSCLI originates from Microsoft Corporation, the contained source code is designed to build on Win32, Mac OS X and other FreeBSD-based distributions.

the Role of the Shared Source CLI (SSCLI)

Before we can begin creating our own custom .NET assemblies (see previous issue) our first task is to obtain a viable implementation of the CLI. For the time being we will concentrate on a research-focused distribution provided by Microsoft named the SSCLI (which also is referred to by its code name Rotor). The SSCLI is 'research-focused' in that it is not intended to be used to as a production level development platform (though on some levels, it most certainly could be), but rather as a tool to explore the C# programming language and the technologies defined by the CLI itself.

The SSCLI does not ship with an implementation of ADO.NET (.NET's data access API), ASP.NET (.NET's Web development API) or Windows Forms (.NET's GUI desktop API). On the plus side, the SSCLI does supply a fully functionality C# compiler, a JScript.NET compiler (which is, in fact, written using C#), a VES implementation and core class libraries (described a bit later in this article). As you would also expect, the SSCLI ships with a number of command line utilities (security tools, compilers, assembly-tweaking tools and so forth) that allow you to interact with the platform itself.

The source code contained within the SSCLI is a blend of C++, C# and assembler instructions (used for only the very lowest of low-level OS-specific details). A majority of the C++ code represents a key aspect of the SSCLI termed the Platform Adaptation Layer (PAL), which abstracts away OS-specific details (more details in just a moment). On a related note, the C++ programming language is used to build the C# compiler. Beyond this however, C# makes up a majority of the source code, which is used to implement a vast majority of the SSCLI base class libraries as well as the JScript.NET compiler.

Rest assured that by taking the time to work with the SSCLI, you will not only gain a solid understanding of the C# programming language, but core aspects of the .NET runtime engine and the programming tools you will make use of on a daily basis. As you would guess, this will provide an excellent foundation when examining other implementations of the CLI such as Portable .NET, Mono and Microsoft's CLR.

Defining 'Shared Source'

The 'SS' in SSCLI refers to the fact that the code base may be extended, modified, hacked, compiled and shared among developers. Thus, if you wish to add additional functionality to the C# compiler, change the way the execution engine handles memory allocations or use the code representing the JScript.NET compiler as the basis for a new .NET language compiler (Logo.NET anyone?), you may do so! However, what you may not do is redistribute a modified SSCLI code base for monetary profit (after all, shared source is not quite open source).

Throughout this series, it is my assumption is that most of you are more interested in using the SSCLI as a vehicle to understand the .NET platform and C# language rather than to alter the existing code base. Given this, I do not intend to spend too much time drilling into the low-level SSCLI implementation code, unless it provides insights into the discussion at hand (whatever that may be). However if you do intend to tweak and recompile the SSCLI source code files, be sure to read the (one-page) license agreement (license.txt) located under the root /sscli folder. Here you will find more details regarding the shared source mindset.

Your Friend, the PAL

As mentioned, a major chunk of C++ source code represents the Platform Adaptation Layer, or PAL. The role of the PAL is to emulate a subset of the Win32 APIs for use on diverse operating systems. The operative word in that last sentence is subset. Basically, the PAL is a platform neutral API which exposes core services such as file IO, networking services, error handling, threading and so forth. The trick however is that although the names of these functions map directly to Win32 APIs, their implementation will differ wildly based on the underlying target operating system.

The next point to be made regarding the PAL is the fact that the /sscli/pal folder contains two subdirectories: unix and win32. As you would guess, if the SSCLI were built on a Win32-based machine, the code within the win32 folder is used to build the PAL. Under Unix-based systems (which of course includes Mac OS X's Darwin), the unix folder is consulted during the compilation process. In either case, it is worth mentioning that not all of the functions defined by the PAL have an exact match in the Win32 API. To be sure, there are a small number of functions (all of which have the 'PAL_' prefix), which are particular to the SSCLI itself.

Again, if you don't intend to modify the SSCLI or port the code base to a new operating system, you can basically be blissfully unaware of the gory details regarding the Platform Adaptation Layer. However, if you wish to take a detailed look at the functions defined by the PAL, you can read the "PAL guide" which is documented in /sscli/docs/techinfo/pal_guide.html. If you wish to view the exact C++ header file that prototypes each function (and the related C++ structures, enumerations and typedefs), examine the rotor_pal.h file located under the /sscli/pal folder.

Downloading the SSCLI

To obtain the SSCLI, launch your Web browser of choice (Safari, of course) and navigate to http://msdn.microsoft.com/net/sscli. Scroll down to the end of this page and download the files listed in Table 1 to your folder of choice. Be very aware that the SSCLI will not build if the local directory path contains any spaces. Therefore a subfolder in your Developer folder named "My_DotNet_Stuff" is fine, while "My Dot Net Stuff" is quite problematic as far as the build process is concerned (this is true of Unix builds in general).

File to Download           Meaning In Life  
sscli_20021101.tgz         This file contains the code needed to build a working implementation of 
                           the CLI, including C# and JScript.NET compilers.
                           
sscli_ref_20021101.tgz     This file extracts to an HTML based class library browser that documents 
                           all of the types supplied by the SSCLI.  

Table 1. The file of the SSCLI

As you will surly notice, the size of these files are quite large. Again, given that the SSCLI is a research-focused implementation of the CLI, you will be downloading a huge amount of raw source code. Later in this series when we shift away from the SSCLI to a 'real-world' implementation of the CLI (such as Portable .NET) you will be pleased to find more manageable downloads.

Obtaining and Installing Tcl/Tk

Before you unpack and build the SSCLI, you will also want to make sure that your Macintosh development machine is equipped with Tcl/Tk. First two questions: "What is Tcl/Tk and why do I need it?" Tcl/Tk is a GUI toolkit and scripting language that can be used to build traditional desktop applications. As mentioned, the SSCLI does not ship with an implementation of Windows Forms, however several sample applications make use of the Tk 8.4.0 widget set to illustrate how the SSCLI can be extended to support alternative GUI toolkits. Therefore, if you wish to run the supplied Tcl/Tk samples (which we will do at a later time), you will need to install this Unix package.

Next question: "Where do I obtain Tcl/Tk?" www.scriptics.com is the official web site for Tcl/Tk, and from here you can download the latest binaries. If you prefer a Mac-friendly alternative however, you can make use of Fink (and/or Fink Commander) to download and install Tcl/Tk with minimal fuss and bother.

This leads me to address the final possible question you might have at this point: "What is Fink?" (if you already know the answer, feel free to begin your download now). Given that the Mac OS is a Unix-based operating system, the Fink project was created to provide a simple way to install Unix software on the Macintosh. While Fink is a command line driven tool, the complementary Fink Commander application provides a GUI shell to the same functionality (both can be downloaded from http://fink.sourceforge.net). Assuming you have Fink Commander up and running, simply do a search for Tcl (Figure 1) and install the tcltk binary using the Binary | Install menu option.


Figure 1. Obtaining Tcl/Tk via Fink Commander

Once you have installed this package, you will find libtcl8.4.dylib and libtk8.4.dylib libraries have been installed (by default) under your /sw/lib folder.

Building the SSCLI

Due to the fact that you are reading MacTech, you are no doubt a software developer (hobbyist or otherwise), and given this fact, I'd bet you have latest and greatest Mac OS programming environment. Nevertheless, do know that the SSCLI expects the following minimal software/hardware requirements:

  • Mac OS X version 10.2 or higher.

  • The Apple Developer Tools.

  • The BSD subsystem installed (this is done by default when installing OS X).

  • 256 MB memory at minimum, 512 MB (recommended), 1 GB (the best!).

  • One gigabyte of free disk space (remember...this is a research distribution).

Building the SSCLI is very straightforward and only involves interacting with two files: env.csh and buildall. Env.csh is a Unix-based shell script that defines a number of platform-specific environment variables required by the SSCLI. The buildall file, as you would expect, is a script that drives the build process for each of the contained subdirectories. This being said, perform the following steps to build the SSCLI on your development machine:

  • Extract sscli_20021101.tgz (either StuffIt or the gnutar utility will do).

  • Open a Terminal and navigate to the sscli directory.

  • Source the env.csh file at the command line (e.g., type: source env.csh).

  • Finally, build the SSCLI by typing ./buildall (within the same Terminal session).

At this point, the build process begins and will continue for some time (now would be a good time to catch up on your e-mails or other such ToDos). If you are interested in examining further details of the build process, check out the building_sscli.html, env.html and buildall.html documents located under sscli/docs/buildtools/. In any case, once the build process is complete, your Macintosh development machine is ready to plunge into the .NET universe.

Learning the Lay of the Land

Next up, let's take a moment to examine the generated directory structure. Using the Finder, open up the root directory of your SSCLI installation. To be sure, the installation process generates an elaborate directory structure, however Table 2 describes some of the key folders to be mindful of.

SSCLI Subfolder                          Meaning In Life  
/build/v1.ppcfstchk.rotor                This is the root folder that contains the compiled tools 
                                         and various SSCLI class libraries.  
                                         
/build/v1.ppcfstchk.rotor/assembly/GAC   The location of the Global Assembly Cache (GAC) that 
                                         contains a number of 'shared' assemblies. As seen in a 
                                         later article, a single copy of a shared assembly can be 
                                         consumed by multiple .NET client applications.   
                                         
/build/v1.ppcfstchk.rotor/config         Contains various XML-based SSCLI configuration files.   

/clr/src/bcl/system                      Contains the C# source code files for the base class 
                                         libraries.   
                                         
/clr/src/csharp                          Contains the C++ source code

/clr/src/ilasm                           for the C# compiler (csc), CIL

/clr/src/ildasm                          compiler (ilasm) and CIL

/clr/src/fusion                          dissassembler (ildasm). The fusion subfolder contains 
                                         code that allows the SSCLI to bind to specific version of 
                                         a .NET assembly (more details later).  
                                         
/docs                                    You guessed it, here are a number of HTML based 
                                         documentation files for the C# compiler, SSCLI development 
                                         tools and the underlying infrastructure. The index.html 
                                         file (located in /docs) is the 'home page' for all other 
                                         documentation.  
                                         
/jscript                                 C# source code for the JScript.NET compiler. 

/pal                                     C++ source code for the Platform Adaptation Layer (PAL).

/samples                                 Various sample programs to build, modify and execute 
                                         within the SSCLI.  
                                         
/tests                                   Numerous source code files that can be used to test a 
                                         modified SSCLI distribution.   
                                         
/tools                                   These are tools used during the build process of the SSCLI, 
                                         not tools for building SSCLI applications!  

Table 2. A partial listing of /sscli subdirectories

A few pages ago, you were introduced to the role of the /pal folder. I would also like to encourage you to check out the /samples folder. Here you will find numerous C# sample applications that illustrate programming with the SSCLI base class libraries (/sscli/samples/samples_index.html provides details regarding each sample application).

The next folder to be aware of at this point is the all-important /docs folder and the index.htm file it contains. When you open this file, you will find an exhaustive list of all of the documentation files for this CLI distribution. I highly recommend you save this file to your browser's Favorites list, as you will come here time and time again to learn about the tools, samples and technologies provided by the SSCLI.

Installing the SSCLI Online Documentation

The next configuration task is to extract the SSCLI online help contained within sscli_ref_20021101.tgz. Once you have extracted this binary (again, either StuffIt or gnutar will do), you will find a file named ClassLibrary.html within the root directory. As you would guess, this file contains links to each of the namespaces of the SSCLI, the highlights of which can be seen in Table 3.

Navigating the HTML-based help system is simple. To take things out for a test drive, click on the System.Xml link located towards the bottom of ClassLibrary.html. Once you do, you will find a 'home page' for the selected namespace, followed by a list of each type it contains (recall from the previous issue, the term 'type' is a generic way to describe classes, interfaces, enumerations, structures and delegates). Next, click on the XmlTextReader class type link. As you can see (Figure 2) you are provided with a C# definition and description of the type as well as the set of members it supports.

SSCLI Namespace                                      Meaning In Life

System.CodeDom.Compiler                            'Code DOM' is a very interesting technology which 
System.CodeDom                                     allows you to represent .NET coding constructs in 
                                                   language neutral terms, and dynamically generate 
                                                   and compile the persisted source code. 
                                                   
System.Collections.Specialized                     The collection-centric namespaces provide numerous 
System.Collections                                 types (ArrayList, Hasttable, etc) that allow you 
                                                   to manage other types.
                                                   
System.ComponentModel                              This namespace defines types that allow you to 
                                                   establish how your custom components should be 
                                                   treated at runtime (and possibly at design time).

System.Configuration.Assemblies                    As you will see later, .NET assemblies can be 
System.Configuration                               configured using XML-based configuration files.  
                                                   These namespaces define types that allow you to 
                                                   interact with these files programmatically.

System.Diagnostics.SymbolStore                     These are fairly low-level namespaces that define 
System.Diagnostics                                 types that allow you to programmatically interact 
                                                   with debugging and tracing details.

System.Globalization                               Here you will find types that help you deal with 
                                                   issues of internationalization.
                                                   
System.IO.IsolatedStorage                          As you would guess, the System.IO-centric 
System.IO                                          namespaces allow you to interact with your 
                                                   machine's directory structure.
                                                   
System.Net.Sockets                                 Namespaces that allow you to program against 
System.Net                                         various network protocols.   

System.Reflection.Emit                             The reflection namespaces allow you to dynamically 
System.Reflection                                  investigate, and generate, types at runtime.   

System.Resoruces                                   Contains types which allow you to embed resources 
                                                   (such as string literals) into a given 
                                                   .NET assembly.
                                                   
System.Runtime.CompilerServices                    You will never care about this namespace unless 
                                                   you are interested in building a .NET-aware 
                                                   compiler.
                                                   
System.Runtime.InteropServices.Expando             Interoperability is the term used to describe the 
System.Runtime.InteropServices                     process of communicating with native libraries from 
                                                   within a .NET code base.  These namespaces provide 
                                                   types for such a task.  
                                                   
System.Runtime.Remoting.Activation                 The SSCLI provides numerous namespaces that allow 
System.Runtime.Remoting.Channels.http              you to build distributed systems using the .NET      
System.Runtime.Remoting.Channels.Tcp               remoting architecture.
System.Runtime.Remoting.Channels
System.Runtime.Remoting.Contexts
System.Runtime.Remoting.Lifetime
System.Runtime.Remoting.Messaging
System.Runtime.Remoting.Metadata.W3cXsd2001
System.Runtime.Remoting.Metadata
System.Runtime.Remoting.MetadataServices
System.Runtime.Remoting.Proxies
System.Runtime.Remoting.Services
System.Runtime.Remoting 

System.Runtime.Serialization.Formatters.Binary     As you will see in later articles, the SSCLI 
System.Runtime.Serialization.Formatters.Soap       provides a very sophisticated (but surprisingly 
System.Runtime.Serialization.Formatters            simple) object serialization architecture.

System.Security.Permissions                        As you would guess, these namespaces provide types 
System.Security.Policy                             that allow you to interact with the .NET 
System.Security.Principal                          security model.
System.Security 

System.Text.RegularExpressions                     Regular expressions manipulation namespaces also 
System.Text                                        ship with the SSCLI.     

System.Threading                                   The System.Threading namespace defines types that 
                                                   allow you to create and manipulate multi-threaded 
                                                   applications.
                                                   
System                                             System is the root namespace in the SSCLI class 
                                                   libraries.  Here you will find a number of utility 
                                                   types (Math, TimeZone, GC and so on), intrinsic 
                                                   data types (String, Int32, Boolean) and common 
                                                   exceptions.  

System.Xml.Schema                                  The SSCLI supplies a number of namespaces that 
System.Xml.Serialization                           allow you to generate, read and manipulate 
System.Xml                                         XML-based data.
System.Xml.XPath
System.Xml.Xsl 

Table 3. The SSCLI Base Class Libraries


Figure 2. Reading up on the XmlTextReader type.

I would also greatly encourage you to add the ClassLibrary.html link to your browser's Favorites list. Over the lifetime of this series, I am assuming you will dive in and check out details I do not have the space to directly cover on your own accord.

Setting Your a Development Environment

At this point I'm sure you are ready to build .NET applications using the SSCLI, however I have two final configuration settings, which while not required, will no doubt make your programming time more productive. The first tip is to define a set of shell aliases that allow you to quickly enable the SSCLI development environment (Listing 1). Using your text editor of choice, update your .tcshrc file with the following:

Listing 1. Defining shell aliases

# Change to SSCLI directory.
alias GoSscli 'cd ~/Web_Downloads/CLI/sscli'
# Change to SSCLI and source the env.csh file
alias DoSscli 'GoSscli; source env.csh'

The first alias, GoSscli, can be typed into a Macintosh Terminal to quickly navigate to the directory containing the SSCLI (of course, your path may vary, so modify accordingly). The second alias, DoSscli, leverages the first alias to change to the SSCLI directory and sources the env.csh file to establish the necessary environment variables. To be sure, when you intend to interact with any of the SSCLI command line tools (including the C# compiler) you must source this script or else contend with the dreaded "command not found" error.

To test your shell updates, close your current Terminal to commit the changes, open a new Terminal and execute the DoSscli command. You should see something like the following (Listing 2):

Listing 2: The result of commanding DoSscli

Last login: Thu Oct 9 14:32:48 on ttyp1
Welcome to Darwin!
[Andrew-Troelsens-Computer:~]andrewtroelsen% DoSscli                                                  
Fastchecked Environment

Now, type in the following command to see the list of options of the C# compiler:

csc -help

If all is well, you should find output similar to that of Figure 3.


Figure 3. Options of the C# Compiler

Configuring Project Builder

The final shortcut you will most likely wish to do is to enable Project Builder to edit C# code files. This one is a no-brainer, simply create a new file with a *.cs file extension (or locate one of the existing files provided by the SSCLI) and double click on the icon. From the resulting dialog box, simply choose Project Builder as the default application.

You will notice that Project Builder seems to recognize the syntax of C#, however don't get your hopes up. While code comments and string literals are realized, C#-specific keywords (such as 'namespace', 'using' or 'unsafe') do not receive such color-coding. Nevertheless, using Project Builder to edit C# code is an appealing alternative to command line editors such as vi or pico (at least in my opinion!)

The Basic Flow of SSCLI Development 

Excellent! If you are still with me, you are now all set to build your first .NET application using the C# programming language. Regardless of which aspect of the SSCLI you are exploring or which type of application you are constructing, you will tend to follow a fixed set of tasks:

  • Ensure you are working within a Terminal that has the SSCLI environment variables activated (thus the reason for the DoSscli alias).

  • Send your C# source code (as well as any number of command line arguments) into the C# compiler, csc.

  • Run your executable application using the Common Language Infrastructure Execution tool, clix.

Let's close this article with a complete example.

Building your First .NET Application

Our goal in this section is to create a code library (myLib.dll) that is consumed by a client application named myClient.exe. As briefly noted in the previous issue, .NET assemblies which end in a *.dll extension cannot be directly loaded by the runtime, but are rather loaded on demand by the client executable which request their services (you'll see many more details regarding .NET binaries and C# later in the series, so don't sweat the details).

Creating MyLib.dll

To begin, create a file named myLib.cs and author the following C# namespace definition (Listing 3):

Listing 3: Your C#-based .NET code library.

using System;
namespace MyLibrary
{
  public class PlatformInfo
  {
          // Static methods can be called
          // directly at the class level.
    public static void PrintEnvInfo()
    {
              // Use System.Environment to show some stats.
      string info = 
        string.Format("\n.NET version is: {0}.", 
        Environment.Version);
      info += 
        string.Format("\nSystem Directory is: {0}.", 
        Environment.SystemDirectory);
      info += string.Format
        ("\nMilliseconds since last boot: {0}.",
        Environment.TickCount);
      Console.WriteLine("*Your System Information*");
      Console.WriteLine(info);
    }
  }
    
  public class MyMathClass
  {
          // Non-static members must be called at the 
          // object level.
    public int AddNumbers(int x, int y)
    {return x + y;}
    public int SubNumbers(int x, int y)
    {return x - y;}
    public int MultiNumbers(int x, int y)
    {return x * y;}
    public int DivideNumbers(int x, int y)
    {return x / y;}
    public string WhichIsBigger(int x, int y)
    {
      return string.Format("{0} is bigger!", 
        Math.Max(x, y));
    }
  }
}

Surprisingly, this trivial namespace definition illustrates a number of aspects of the C# language. First, recall from the previous article that the C# namespace keyword defines a conceptual boundary for a set of related types, while the using keyword allows you to access types contained within another namespace. Here, the MyLibrary namespace defines two class types (in contrast to Java, a single C# source code file may define any number of types, whose names do not need to map to the name of the physical source code file).

The public PlatformInfo class defines a single static method named PrintEnvInfo(). As you most likely already know, static type members can be called directly from the class level without the need to manually create an object in memory. The implementation of this method makes use of the static string.Format() method to build a string containing various bits of information regarding the current development machine. Recall from the previous installment of this series that the curly bracket syntax (e.g. '{0}') signifies a placeholder for dynamic string building (slightly akin to the C printf() function).

The MyMathClass defines a set of instance level methods that manipulate two integer parameter types. As detailed in a future issue, the C# programming language defines a number of keywords which are shorthand notations for true blue types in the System namespace. Here, the C# 'int' keyword represents a System.Int32 structure type. Next notice that the WhichIsBigger() method leverages the static Math.Max() method to return a stylized string. Finally, in the case of each class implementation, notice that C# honors the C, C++, Objective C and Java style escape characters such as '\n'.

Now, at the command line, compile this file into a .NET class library as so (Listing 4):

Listing 4: Compiling a C#-based code library

csc /t:library mylib.cs

Here, we are instructing the C# compiler to generate a class library *.dll file (via /t:library) given an input file named mylib.cs. By default, the name of the *.dll is based on the name of the first input file, thus upon successful compilation, you should have a new .NET assembly named myLib.dll.

Creating myClient.exe

Now that we have a .NET *.dll file, we need to create a client application to make use of it. Given this, create another C# source code file named MyClient.cs which contains the following namespace definition (Listing 5):

Listing 5: The C#-based .NET client application.

using System;
using MyLibrary;
namespace MyClientApp
{   
  public class MyApp
  {
    public static void Main()
    {
              // First show Environment info.
      PlatformInfo.PrintEnvInfo();
        
              // Make a MyMathClass type.
      MyMathClass m = new MyMathClass();
      Console.WriteLine("* Fun with Numbers *");
        
              // Now enter a loop to perform 
              // simple math.
      do
      {
        int x = 0, y = 0;
        Console.WriteLine("Enter two numbers:");
        Console.Write("Number 1: ");
        x = int.Parse(Console.ReadLine());
        Console.Write("Number 2: ");
        y = int.Parse(Console.ReadLine());
        Console.WriteLine(m.WhichIsBigger(x, y));
        Console.WriteLine("{0} + {1} = {2}", 
          x, y, m.AddNumbers(x, y));
        Console.WriteLine("{0} - {1} = {2}", 
          x, y, m.SubNumbers(x, y));
        Console.WriteLine("{0} * {1} = {2}", 
          x, y, m.MultiNumbers(x, y));
        Console.WriteLine("{0} / {1} = {2}", 
          x, y, m.DivideNumbers(x, y));
        Console.Write("Another round? ");
      }while("n" != Console.ReadLine());
    }
  }
}

Again, this simple example proves enlightening. First, given that the client application needs to make use of types located in the System and MyLibrary namespaces, the first lines of code should be clear.

The definition of Main() is important, in that Main() must be static and must have a capital 'M' (as C# is case sensitive). Beyond these restrictions however, the Main() method is quite flexible in that is may (or may not) take an array of strings to represent command line arguments, may (or may not) return an integer to the system, and may be declared public or private. Thus, any of the following Main() methods are a-okay (Listing 6):

Listing 6: The various faces of Main().

public void Main(string[] args) {...}
public void Main() {...}
public int Main() {...}
public int Main(string[] args) {...}
private void Main(string[] args) {...}
private void Main() {...}
private int Main() {...}
private int Main(string[] args) {...}  

Here, our Main() method simply invokes the static PlatformInfo.PrintEnvInfo() method and allocates an instance of the MyMathClass type via the C# new keyword. After this point, a do/while loop is entered to prompt the user for two numbers to pass to the various methods of MyMathClass.

Last but not least, notice how the textual data retrieved from System.Console.ReadLine() is transformed into a 'real' numerical value using the static Parse() method of the System.Int32 structure as seen in Listing 7 (remember! The C# 'int' keyword is nothing more than a shorthand notation for declaring a System.Int32 type):

Listing 7: The C# 'int' and System.Int32 relationship.

// 'x' and 'y' are really of type System.Int32!
int x = 0, y = 0;
Console.WriteLine("Enter two numbers:");
Console.Write("Number 1: ");
// System.Int32 defines a static Parse() method.
x = int.Parse(Console.ReadLine());
Console.Write("Number 2: ");
y = int.Parse(Console.ReadLine());

To compile this file into an executable binary requires the following command set (Listing 8):

Listing 8: Building a .C#-based executable.

csc /t:exe /r:myLib.dll MyClient.cs

Here, we are instructing the C# compiler to generate an executable file (via /t:exe) which references types contained within myLib.dll (via /r:myLib.dll) given the input file named MyClient.cs.

Observing the Fruits of your Labor

Unlike a native Macintosh application, you cannot simply double click on MyClient.exe to launch the client binary. When working within the confines of the SSCLI, you need to bootstrap .NET executable assemblies using the CLI Execution utility (clix.exe) as seen in Listing 9:

Listing 9: All good things do come.

clix myclient

Once you have done so, you can manipulate integers to your hearts content (Figure 4).


Figure 4. Your first .NET Application

Wrap Up

So then! At this point you (hopefully) have succeeded in your installation of the SSCLI and the first compilation of your .NET lifestyle. Over the course of this issue, you have been provided with an overview of various subfolders within the /sscli root directory, the use of the HTML-based help system and select command line tools. In the next issue, you will come to know the details of the C# compiler, investigate several of the supplied sample applications and forge ahead with your understanding of C#. Until next month, happy hacking!


Andrew Troelsen is a seasoned .NET developer who has authored numerous books on the topic, including the award winning C# and the .NET Platform. He is employed as a full-time .NET trainer and consultant for Intertech Learning (www.intertechlearning.com) and spends his idle moments at home playing far too many video games. You can contact Andrew at atroelsen@mac.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Tor Browser 12.5.5 - Anonymize Web brows...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Malwarebytes 4.21.9.5141 - Adware remova...
Malwarebytes (was AdwareMedic) helps you get your Mac experience back. Malwarebytes scans for and removes code that degrades system performance or attacks your system. Making your Mac once again your... Read more
TinkerTool 9.5 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Paragon NTFS 15.11.839 - Provides full r...
Paragon NTFS breaks down the barriers between Windows and macOS. Paragon NTFS effectively solves the communication problems between the Mac system and NTFS. Write, edit, copy, move, delete files on... Read more
Apple Safari 17 - Apple's Web brows...
Apple Safari is Apple's web browser that comes bundled with the most recent macOS. Safari is faster and more energy efficient than other browsers, so sites are more responsive and your notebook... Read more
Firefox 118.0 - Fast, safe Web browser.
Firefox offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals and casual... Read more
ClamXAV 3.6.1 - Virus checker based on C...
ClamXAV is a popular virus checker for OS X. Time to take control ClamXAV keeps threats at bay and puts you firmly in charge of your Mac’s security. Scan a specific file or your entire hard drive.... Read more
SuperDuper! 3.8 - Advanced disk cloning/...
SuperDuper! is an advanced, yet easy to use disk copying program. It can, of course, make a straight copy, or "clone" - useful when you want to move all your data from one machine to another, or do a... Read more
Alfred 5.1.3 - Quick launcher for apps a...
Alfred is an award-winning productivity application for OS X. Alfred saves you time when you search for files online or on your Mac. Be more productive with hotkeys, keywords, and file actions at... Read more
Sketch 98.3 - Design app for UX/UI for i...
Sketch is an innovative and fresh look at vector drawing. Its intentionally minimalist design is based upon a drawing space of unlimited size and layers, free of palettes, panels, menus, windows, and... Read more

Latest Forum Discussions

See All

Listener Emails and the iPhone 15! – The...
In this week’s episode of The TouchArcade Show we finally get to a backlog of emails that have been hanging out in our inbox for, oh, about a month or so. We love getting emails as they always lead to interesting discussion about a variety of topics... | Read more »
TouchArcade Game of the Week: ‘Cypher 00...
This doesn’t happen too often, but occasionally there will be an Apple Arcade game that I adore so much I just have to pick it as the Game of the Week. Well, here we are, and Cypher 007 is one of those games. The big key point here is that Cypher... | Read more »
SwitchArcade Round-Up: ‘EA Sports FC 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 29th, 2023. In today’s article, we’ve got a ton of news to go over. Just a lot going on today, I suppose. After that, there are quite a few new releases to look at... | Read more »
‘Storyteller’ Mobile Review – Perfect fo...
I first played Daniel Benmergui’s Storyteller (Free) through its Nintendo Switch and Steam releases. Read my original review of it here. Since then, a lot of friends who played the game enjoyed it, but thought it was overpriced given the short... | Read more »
An Interview with the Legendary Yu Suzuk...
One of the cool things about my job is that every once in a while, I get to talk to the people behind the games. It’s always a pleasure. Well, today we have a really special one for you, dear friends. Mr. Yu Suzuki of Ys Net, the force behind such... | Read more »
New ‘Marvel Snap’ Update Has Balance Adj...
As we wait for the information on the new season to drop, we shall have to content ourselves with looking at the latest update to Marvel Snap (Free). It’s just a balance update, but it makes some very big changes that combined with the arrival of... | Read more »
‘Honkai Star Rail’ Version 1.4 Update Re...
At Sony’s recently-aired presentation, HoYoverse announced the Honkai Star Rail (Free) PS5 release date. Most people speculated that the next major update would arrive alongside the PS5 release. | Read more »
‘Omniheroes’ Major Update “Tide’s Cadenc...
What secrets do the depths of the sea hold? Omniheroes is revealing the mysteries of the deep with its latest “Tide’s Cadence" update, where you can look forward to scoring a free Valkyrie and limited skin among other login rewards like the 2nd... | Read more »
Recruit yourself some run-and-gun royalt...
It is always nice to see the return of a series that has lost a bit of its global staying power, and thanks to Lilith Games' latest collaboration, Warpath will be playing host the the run-and-gun legend that is Metal Slug 3. [Read more] | Read more »
‘The Elder Scrolls: Castles’ Is Availabl...
Back when Fallout Shelter (Free) released on mobile, and eventually hit consoles and PC, I didn’t think it would lead to something similar for The Elder Scrolls, but here we are. The Elder Scrolls: Castles is a new simulation game from Bethesda... | Read more »

Price Scanner via MacPrices.net

Clearance M1 Max Mac Studio available today a...
Apple has clearance M1 Max Mac Studios available in their Certified Refurbished store for $270 off original MSRP. Each Mac Studio comes with Apple’s one-year warranty, and shipping is free: – Mac... Read more
Apple continues to offer 24-inch iMacs for up...
Apple has a full range of 24-inch M1 iMacs available today in their Certified Refurbished store. Models are available starting at only $1099 and range up to $260 off original MSRP. Each iMac is in... Read more
Final weekend for Apple’s 2023 Back to School...
This is the final weekend for Apple’s Back to School Promotion 2023. It remains active until Monday, October 2nd. Education customers receive a free $150 Apple Gift Card with the purchase of a new... Read more
Apple drops prices on refurbished 13-inch M2...
Apple has dropped prices on standard-configuration 13″ M2 MacBook Pros, Certified Refurbished, to as low as $1099 and ranging up to $230 off MSRP. These are the cheapest 13″ M2 MacBook Pros for sale... Read more
14-inch M2 Max MacBook Pro on sale for $300 o...
B&H Photo has the Space Gray 14″ 30-Core GPU M2 Max MacBook Pro in stock and on sale today for $2799 including free 1-2 day shipping. Their price is $300 off Apple’s MSRP, and it’s the lowest... Read more
Apple is now selling Certified Refurbished M2...
Apple has added a full line of standard-configuration M2 Max and M2 Ultra Mac Studios available in their Certified Refurbished section starting at only $1699 and ranging up to $600 off MSRP. Each Mac... Read more
New sale: 13-inch M2 MacBook Airs starting at...
B&H Photo has 13″ MacBook Airs with M2 CPUs in stock today and on sale for $200 off Apple’s MSRP with prices available starting at only $899. Free 1-2 day delivery is available to most US... Read more
Apple has all 15-inch M2 MacBook Airs in stoc...
Apple has Certified Refurbished 15″ M2 MacBook Airs in stock today starting at only $1099 and ranging up to $230 off MSRP. These are the cheapest M2-powered 15″ MacBook Airs for sale today at Apple.... Read more
In stock: Clearance M1 Ultra Mac Studios for...
Apple has clearance M1 Ultra Mac Studios available in their Certified Refurbished store for $540 off original MSRP. Each Mac Studio comes with Apple’s one-year warranty, and shipping is free: – Mac... Read more
Back on sale: Apple’s M2 Mac minis for $100 o...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $100 –... Read more

Jobs Board

Licensed Dental Hygienist - *Apple* River -...
Park Dental Apple River in Somerset, WI is seeking a compassionate, professional Dental Hygienist to join our team-oriented practice. COMPETITIVE PAY AND SIGN-ON Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Sep 30, 2023 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
*Apple* / Mac Administrator - JAMF - Amentum...
Amentum is seeking an ** Apple / Mac Administrator - JAMF** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Child Care Teacher - Glenda Drive/ *Apple* V...
Child Care Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.