'GitHub flavored markdown code syntax highlighting forcing type
Take this simple code markdown:
```cs
var x = new Locked<Rec>(new ("John", 35));
```
This renders in GitHub readme like this:
I now just add a definition:
```cs
record Rec(string Name, int Age);
var x= new Locked<Rec>(new ("John", 35));
```
and it now renders like this:
As you can see the type Locked and the new are for some reason no longer coloured purple. Why is this and how can I get around it ?
Solution 1:[1]
Visual Studio Code does the same thing.
I'm not a C# developer, but the examples I found all instantiate the record inside Main:
```cs
record Rec(string Name, int Age);
public static void Main()
{
var x = new Locked<Rec>(new ("John", 35));
}
```
This seems to get both VSCode and GitHub to highlight syntax as you expect:
It works even better if you declare the record inside Main as well:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris |




