The absolute state of C#

microsoft pajeets on suicide watch
if (true) {
int x = -1;
}
int x = 1; //compiler error

Attached: 1494280181551.png (327x316, 165K)

Other urls found in this thread:

en.wikipedia.org/wiki/Local_variable
en.wikipedia.org/wiki/Scope_(computer_science)
developer.mozilla.org/en-US/docs/Glossary/Hoisting
benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharpcore-gpp.html
techempower.com/benchmarks/#section=test&runid=d995c1ca-2918-4587-b668-2fc66635018a&hw=ph&test=plaintext
twitter.com/NSFWRedditVideo

Uhhhh this code is stupid though so it's good the compiler notices it's stupid

var y = String.format("{356}", "lol"); // 0 errors, 0 warnings

holy shit i dont even like c# but stop posting this code every 5 minutes on this fucking chinese image board for fucks sake

Didn't microshit teach you about scoping and local variable in your online shilling class?

You are retarded OP. Of course that should be a compile-time error, it's declaring the same variable twice.

>what are scopes

This just in: Microsoft compilers are smart and work as intended. More at 11. Back to you John.

...

>It is an error for a local variable declaration space and a nested local variable declaration space to contain elements with the same name.

it's by design

>scopes within an if statement
>I'll declare this variable if something something otherwise I won't
Isn't that what macros do?

Non-shit programming languages have scoping you code monkey morons.
#include

int main(){
if(1){
int x = 1;
printf("%i \n",x);
}
int x = -1;
printf("%i \n", x);
}

perfectly valid C code. The first declaration is supposed to be local to the if block.

So what should this do then?
if (true) {
string x = "test";
}
Console.WriteLine(x);

It's amazing microcucks don't understand lexical scoping

How are these c# retards so retarded?
are they all unity gamedevs?

nothing because "x" is not in the local space. if you use a variable name in local space you can't use it again in nested scope.

Total brainlet

That printing function is not in a nested scope you drooling retard, it's the outer scope. C# doesn't understand scoping.

If they were smart they wouldn't be using C#

WTF HAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

OH NONONONONO HAHAHAHAHAHAHAHAHAHHAHAHAHAHHAHA

Attached: 1549755834302.jpg (425x283, 18K)

you can't shadow variables in C#, sorry you can't get that simple fact through your thick fucking skull

That's what you get for reusing variable names like a fucking nigger.

It should throw error because the code is atrocious. You cannot declare a variable inside a scope and then use variable outside of the scope.

Didn't your mother ever teach you about scope?

You're a brainlet.

php-kun please go

>WTF
Same as in C, it's a fucking format string. Deprecated in favor of string interpolation.

Strange, looks like if doesn't create a scope, because

using System;

public class Test
{
public static void Main()
{
{int x=0;}
{int x=1;}
}
}

works just fine.

>retard forgets the difference between declaration and definition

String format is not deprecated. Your lang is trash that's what it is

Attached: Screenshot from 2019-08-01 11-36-30.png (3176x1012, 101K)

Does C# cause brain damage?
en.wikipedia.org/wiki/Local_variable
en.wikipedia.org/wiki/Scope_(computer_science)

Attached: 1545505078487.png (817x891, 32K)

>format!
Doesn't even do the same thing, tranny, C and C# format strings can be defined in runtime.

>>what are scopes
>implying c# considers if statements scopes
How do you not choke on your own spit?

Attached: crossed arms gator.png (1012x1048, 693K)

Holy fuck, the thread is full of brainlets. C#, like many other languages, moves all variable declarations to the top of the scope, so the code in OP effectively becomes

int x = 1;
if (true) {
int x = -1;
}

Manually defining a scope solves the issue.

if (true)
{
int x = -1;
}
{
int x = 1;
}

/thread

this is like... C# hello world levels of basic.

>C and C# format strings can be defined in runtime.
Imagine being this inefficient

Format strings for localization. String interpolation for everything else. C# supports both.

>moves all variable declarations to the top of the scope
So C# has no local variables?
No wonder this language is so trash and nobody uses it

>So C# has no local variables?
Please tell me how did you come to this retarded conclusion. I assume you saw this before posting.

If the local variables are "like many other languages", moved to the top of the scope, the variable is not local anymore.

{
let x = "local variable";
use(x);
}

becomes
let x = "global variable";
{
use(x);
}

>like many other languages, moves all variable declarations to the top of the scope,
Also if that's the case,
while (condition)
if (condition)
var tmp = x; use (tmp);

Are you telling me that C# floates that tmp to the outer scope? What kind of shitlang is this?

Never mind I stand corrected, what the FUCK is this shit, C# does use scoping but it seems like it reserves variable names globally.

Attached: gator wat.png (143x164, 40K)

Wrong. You moved a variable out of scope. Read again.

JavaScript allows variable shadowing and I use it all the time. C# is fucking annoying as hell sometimes.

What do you mean? the latter scope has access to x, it is in the scope since it was declared before the local scope began.

Any sane language allows shadowing.
C# scopes are half assed broken straight up

You fucking gorilla nigger(not you alone to be fair), I explained everything already.
void Main()
{//outer fucking scope
if(true)
{//inner fucking scope
int i = -1;
}
int i = 1;//it's in the outer fucking scope
}

get transformed into
void Main()
{//outer fucking scope
int i = 1;//it's in the outer fucking scope
if(true)
{//inner fucking scope
int i = -1;
}
}

>like many other languages
Citation needed. I thought only JavaScript pulled this kind of idiotic bullshit:
developer.mozilla.org/en-US/docs/Glossary/Hoisting

WAIT I JUST LOOKED IT UP
OH NONONONONONONONONONONO
AHAHAHAHAHAHAHAHAHAHAHA

Attached: Screenshot from 2019-08-01 12-09-16.png (1648x1504, 154K)

It will either crash or print a bunch of garbage because x isn't even declared.

>Reordering variable declarations
What a shitlang hahaahahaha
OH
OOH
HAHAHAHA

String interpolation is just a sugar for string format. I can't believe string formatting is done on runtime in C shart

then again it's one of the slowest langauges out there

shoulda used lisp

>String interpolation is just a sugar for string format.
Completely the opposite, read the docs of your trannylang first.

It's dumb but it makes sense when you know what's happening. Meanwhile JS does the same thing yet allows it, if that's not fucking broken I don't know what is.

Cope harder pajeet, enjoy your runtime crashes

Attached: Screenshot from 2019-08-01 12-18-50.png (1790x742, 72K)

It's intentional, silly

>conveniently switches the language to avoid the issue

Issue is in your pajeet lang, not in Rust or C++, D or Go or any other properly designed language.

Compile-time implementations, like the ones you posted, don't do the same thing format strings in C# do and they're implemented by using string interpolation.

What the fuck?
Do you mean
public class Program
{
public static void Main()
{
while(true) {
if (condition)
break;
else
int x = heavyFunctionOnRuntime();
}
}
}

becomes
public class Program
{
public static void Main()
{
int x = heavyFunctionOnRuntime();
while(true) {
if (condition)
break;
}
}
}

Attached: 1549453119433.jpg (450x450, 28K)

You've posted this for a week straight now in /dpt/.

Wait does it become
public class Program
{
public static void Main()
{
while(true) {
int x = heavyFunctionOnRuntime();
if (condition)
break;
}
}
}

Every variable here is already on top of scope, omitting braces for one-liners doesn't actualy make them disappear, you know.
public class Program
{
public static void Main()
{
while(true) {
if (condition){
break;
}
else{
int x = heavyFunctionOnRuntime();
}
}
}
}
[/code[

AHAHAH NONONONONONONONOOOO
public static void Main()
{
while(true) {
if (condition)
break;
// do things
int x = heavyFunction();
}

// becomes
while(true) {
int x = heavyFunction();
if (condition)
break;
// do things
}
}

Good point, I correct myself then - variable DECLARATION is moved to the top of scope.
public static void Main()
{
while(true) {
if (condition)
break;
// do things
int x = heavyFunction();
}
}

becomes
public static void Main()
{
while(true) {
int x;
if (condition)
break;
// do things
x = heavyFunction();
}
}

>inb4 it's under break
public static void Main()
{
while(true) {
if (runtimeCondition)
break;
Type x = heavyFunction();
}

// becomes
while(true) {
Type x = heavyFunction();
if (runtimeCondition)
break;
}
}

HURR HURR
while(true) {
if (runtimeCondition)
break;
// do things
InstanceOfHeavyCtorStruct x = heavyFunction();
}
}

while(true) {
InstanceOfHeavyCtorStruct x; // kek
if (runtimeCondition)
break;
// do things
x = heavyFunction();
}

>InstanceOfHeavyCtorStruct x; // kek
Do you seriously think it gets constructed right there? It's simply lexically declared, not initialized.

>then again it's one of the slowest langauges out there
you clearly have no experience if you believe this

Structs don't default to nulls, and you don't know how many object members you need to initialize.

benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharpcore-gpp.html

>Structs don't default to nulls
It's not constructed at all. It's a compile-time thing.

>benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharpcore-gpp.html
>ONE OF THE SLOWEST
>compares it only to C++
uhm ok

C#:
>sbyte
>byte

Also C#:
>int
>sint // lol no

>benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharpcore-gpp.html
Steadily beats its direct competitor(Java). If by "one of the slowest" you meant "slower than C,C++ and Rust", sure.

Good explanation thanks man
you blew this dipship seether out

>The SByte type is not CLS-compliant. The CLS-compliant alternative type is Int16

>Steadily beats its direct competitor(Java).
OH NOO

Attached: 1540203060385.png (1888x1224, 454K)

Slower than trannylang too. Im enjoying every bit of your pajeet tears.

>"damn, he got me, better pull a different benchmark"

Attached: 1551535695155.png (1871x3393, 444K)

Rust is on average faster than C++, of course it's slower than Rust.

Imagine the world where OP is not a fucking retard and can speak like a adequate human being.
Who knows, we might've got an actual conversation here.

>write shitty code
>waaaaaah why did I get a compiler error

One second, isn't C# supposed to be the "better C++"?

Oh NOO OUCH

Attached: Screenshot from 2019-08-01 12-57-02.png (2246x656, 210K)

>>write shitty code
>>waaaaaah why did I get a compiler error
LOL pajeet so why does this compile

>t. memelord
Are you having a laugh? The point is not that C# is any good. The point is I can think of more languages that are orders of magnitude slower than C# then you could probably think of period. But by all means continue making stupid false statements. This is Jow Forums after all.

>C# supposed to be the "better C++"
Nigger what

>One second, isn't C# supposed to be the "better C++"?
How could a language with GC be a "better C++"? Are you out of your mind?

if (condition)
{
// ...
int count = 0;
// count things
}

// ...
int count = 0;
// count other things


Explain why this isn't a totally valid and logical thing to do. It's clear that the two counts are unrelated, and doesn't require touching other parts of the code to move/remove/modify the conditional.

Attached: 1544803702950.png (700x700, 362K)

Apperently C# pushes variable declarations to the top of each scope.
while(true) {
if (runtimeCondition)
break;
// do things
InstanceOfHeavyCtorStruct x = heavyFunction();
}
}
// becomes
while(runtimeCondition) {
InstanceOfHeavyCtorStruct x; // kek
if (runtimeCondition)
break;
// do things
x = heavyFunction();
}

First, you are a dumb retard who is redefining a variable.
Second, "it's clear" because you don't have any code there.
You can reuse local variable names if you explicitly scope them out but it's a bad practice.

>oh no I reused the "count" variable because my langue is trash
Cry harder pajeet your language is fundamentally broken
IFoo qaz = new Bar();
IFoo zomp = new Bar();
if (qaz is Bar b){
}
if (zomp is Bar b){ // error CS0128: A local variable or function named 'b' is already defined in this scope
}

This is especially frustrating with lambdas.

public static void Main(string[] args)
{
Action f = () => {
int x = 0;
};
int x = 0;
}

lol
if (thing is SomeType st)
{
// do something with st
}
// multiple lines of other stuff
if (other_thing is SomeType st) // error, you'll need to rename it st2 or something
{
// do something with st
}

Post an ideone example, you're pulling stuff out of your ass right here.

Nu-male retarded nigger. Learn to scope. Both counts are inside the same scope. The if-statement count is inside a sub-scope of the main scope.

FUCK.

Stop writing shit code any time, user

>Both counts are inside the same scope.
It's not, C shart moves the new variable above the local scope behind your back.
Fuck off ranjeet

b is in the scope of if you autistic gorilla nigger.

cope harder

take a chill pill and simmer down

>cherrypicks skewed DB benchmark instead of the correct one
seriously, dilate tranny

techempower.com/benchmarks/#section=test&runid=d995c1ca-2918-4587-b668-2fc66635018a&hw=ph&test=plaintext

C# is in top 10.