Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the C# compiler allow a duplicated variable in nested scope?

Historically, when developing in .Net I could not duplicate the name of variable in nested scope. However, after recently updating Visual Studio 2019 to version 16.4.2 I have noticed that variable names can be duplicated in nested scope.

For example:

var test = "hello";
Console.WriteLine(test);
var things = new []{"one", "two", "three"};
things.Select(test => // <- test is duplicated here, normally this breaks compilation
{
    Console.WriteLine(test);
    return test;
}).ToList();

// output:
// hello
// one
// two
// three

https://dotnetfiddle.net/h85BK4

Why is this suddenly allowed?

Follow up question: If this is a new language "feature", is there a way to configure Visual Studio to continue to break when a variable is duplicated in nested scope?

like image 830
masterjeef Avatar asked Jan 10 '20 20:01

masterjeef


People also ask

Why does the letter c exist?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.

Does the letter c exist?

C, or c, is the third letter in the English and ISO basic Latin alphabets. Its name in English is cee (pronounced /ˈsiː/), plural cees.

Why does the c make the s sound?

The rule. Here's the rule: When 'c' comes directly before the letters 'e', 'i' or 'y' we use the /s/ sound. in other cases we use a /k/ sound.

Why does c make 2 sounds?

In the Latin-based orthographies of many European languages, including English, a distinction between hard and soft ⟨c⟩ occurs in which ⟨c⟩ represents two distinct phonemes. The sound of a hard ⟨c⟩ often precedes the non-front vowels ⟨a⟩, ⟨o⟩ and ⟨u⟩, and is that of the voiceless velar stop, /k/ (as in car).

Why is the C language called so?

The C language is called so because of a very simple reason. It was named after the language, that was called B. The very first Unix systems were written in low level assembler language. These systems were built for working with PDP-7, the minicomputer, that was introduced in 1965.

Why should I learn C?

Moreover, a lot of the principles used in C – for instance, argc and argv for command line parameters, as well as loop constructs and variable types – will show up in a lot of other languages you learn so you’ll be able to talk to people even if they don’t know C in a way that’s common to both of you.

What is the difference between C and C++?

There is no language called “C/C++”. C and C++ are different languages, although it’s true that C++ is effectively a super-set of C (not a strict super-set, minor differences exist). Having said that, the idiomatic way to write both languages is pretty different, in-fact it’s discouraged to go the C route if your intention is to learn C++.

What does ‘C = do’ mean in music?

What does 'C = do' in music means? Depending on what method you’re using C being Do is a placeholder for the tonic note in a key. The tonic note is the first note of a scale in any given key.


1 Answers

This is a new feature in C# 8.0, local function and lambda parameters can shadow outer names.

like image 90
Sebastian 506563 Avatar answered Oct 14 '22 22:10

Sebastian 506563