1

I have read in the c# language specification :

Source files typically have a one-to-one correspondence with files in a file system, but this correspondence is not required

What does this exactly mean ?

Sinatr
  • 20,892
  • 15
  • 90
  • 319
kkkk00999
  • 179
  • 2
  • 13
  • Interestingly I found a similar definition for other programming languages, where the term `source files` is replaced by `compilation unit`. That term is also mentioned in the C# language definition, but not used here, even though I'd think it would make more sense. – Thorsten Dittmar Jul 15 '16 at 12:09
  • My guess the author want to point out that "what you see is not necessarily what is inside file" and vise-versa. Because something you may not see (new line can be `\n` or `\n\r` or `\r\n`, this you don't see), there are questions around where the problem lies in using special character (invisible character) in `string` literals. – Sinatr Jul 15 '16 at 12:13

3 Answers3

1

As the line before it says:

A source file is an ordered sequence of Unicode characters

That means a "source file" doesn't necessarily have to be a file on the file system. It could be any old stream of bytes that represent characters in UTF-16. It could come from a memory stream, or from a network, or from any old place. But usually it's a file on the file system.

Martijn
  • 11,964
  • 12
  • 50
  • 96
0

I think it literally means that each source file is represented by a single file on the system.

For example, say I have some source code:

Using System;

namespace Test 
{
    public class Program 
    {
        private static void Main (string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

This can be saved to the file system as Program.cs. We now have some source code which is being represented by a single file on the system.

but this correspondence is not required

Suggests that a source file does not always exist on the system. For example, the source could exist as a "sequence of Unicode characters" instead, which could be stored somewhere in memory.

Bassie
  • 9,529
  • 8
  • 68
  • 159
0

With visual studio, you can "link" a source file within a project. If you place a source file in a project, and link the same source file in a different project (i.e. share the same source code in 2 different projects), you end having 2 sources files linked to a single file.

I usually use this feature in solutions having more than one project: the shared source code is something like this:

[assembly: AssemblyVersion("1.2.3.0")]
[assembly: AssemblyFileVersion("1.2.3.0")]

So when complied, every assembly in my solution have the same version number.

Gian Paolo
  • 4,161
  • 4
  • 16
  • 34