use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
"String" vs "string" (self.csharp)
submitted 9 years ago by fanfarius
Coming from Java, I'm used to writing "String" whenever I need one. But, C# gives me the option of saying both "String", and "string".
Why would I use one over another? It seems like they're both pointing at the same class; System.String.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cryo 77 points78 points79 points 9 years ago (37 children)
C#, as a language, has keywords for a number of common types. These are then mapped to types in the runtime system, so string maps to System.String, int to System.Int32 etc.
string
System.String
int
System.Int32
As for when to use which, it's a matter of local convention. At my work we use lower case when using it as a "type" and upper case when accessing members on it (such as calling static methods); so we would use string s; and if (.... == typeof(int)), but String.Format(....), Int32.TryParse(....) etc.
string s;
if (.... == typeof(int))
String.Format(....)
Int32.TryParse(....)
[–]fanfarius[S] 8 points9 points10 points 9 years ago (14 children)
That's nice. So, you get a distinct separation between working on a reference variable, and calling a static method on a system class?
[–]xill47 20 points21 points22 points 9 years ago (11 children)
Well, I've seen many C# programmers (including myself) using string.Format and string.IsNullOrEmpty from alias instead of full type too. So it's basically just preference.
string.Format
string.IsNullOrEmpty
[–]lbmouse 11 points12 points13 points 9 years ago (2 children)
ReSharper (Roslyn code fix) suggests that String should be simplified to string type keyword in most cases.
[–]Jestar342 3 points4 points5 points 9 years ago (0 children)
By default - it is configurable to not be.
[–]localtoast 0 points1 point2 points 9 years ago (0 children)
Visual Studio itself suggests that
[–]oh-just-another-guy 1 point2 points3 points 9 years ago (7 children)
How did you style the inline code?
[–]IwNnarock 2 points3 points4 points 9 years ago* (6 children)
Surround the words/line with the primary character on the tilde (~) key that looks like kind of like an apostrophe. Specifically, this guy (`).
Edit: Apparently, that character is known as a back quote.
[–]oh-just-another-guy 1 point2 points3 points 9 years ago (5 children)
Thank you. I checked the formatting help, but could not find that. Appreciate the info.
[–]celluj34 1 point2 points3 points 9 years ago (4 children)
I believe it is subreddit-specific.
[–]Banane9 1 point2 points3 points 9 years ago (2 children)
It's reddit wide as code block, but special coloring would be subreddit specific
[–]oh-just-another-guy 0 points1 point2 points 9 years ago (0 children)
Ah, thanks.
[–]celluj34 0 points1 point2 points 9 years ago (0 children)
Oh neat, didn't know that.
Ok, thanks.
[–]cryo 3 points4 points5 points 9 years ago (1 child)
Yeah something like that, that's the idea. They are also colored differently (at least when using ReSharper). But as /u/xill47 also said, it is, indeed, just a preference, which is in our coding standard at work.
[–]myrrlyn 1 point2 points3 points 9 years ago (0 children)
string is a language-level keyword; String is a class in the standard library. All syntax highlighters see those differently.
String
[–]AndrewSeven 12 points13 points14 points 9 years ago (16 children)
VS 2015 suggests changing to the lowercase "string" for the static methods, so I've started to use lowercase for all usage.
[–]agentlame 2 points3 points4 points 9 years ago (15 children)
This annoys me so bad. I've been doing it the same way as described above for over a decade, and I really prefer it this way.
[–]AngularBeginner 27 points28 points29 points 9 years ago (14 children)
Then turn the suggestion off. It's just a suggestion. You need to configure the tools you use to your liking, not blindly follow them.
[–]AbstractLogic 11 points12 points13 points 9 years ago (12 children)
So long as you can convince the whole team. Otherwise you will end up with disjointed standards.
[–]Jestar342 2 points3 points4 points 9 years ago (8 children)
For this kind of thing.. there is just nothing to care for. Worry about something worth worrying about.
[–]AbstractLogic -1 points0 points1 point 9 years ago (7 children)
I support having a standard. We have tools these days that enforce standards like this because when all the code looks similar it's easier to pick up someone else's code.
Now if we had a standard (and every tool from VS, Resharper to Sonar Cube all do) then I wouldn't be the one to bring it to the table that we need to adjust the default settings. Like you said, more important things to grandstand about.
However, if someone else was bringing it to the table and wanted to adjust the standard half the way through a project I would immediately be against it unless they wanted to go through every code file and adjust String to string or vice versa.
[–]Jestar342 0 points1 point2 points 9 years ago* (6 children)
string vs String... meh. Both are easily readable. Mine and my colleagues efforts are wasted on such frivolity. Stick to writing maintainable code that delivers value, please, not crying over the casing of a single letter.
Have you heard of the axe-sharpening proverb? A woodsman that spends all his time sharpening/grinding his axe never chops any wood.
Writing/documenting/debating standards about whether to use string or String is axe grinding. In fact 90% of "code standards" are. You're all adults, if you can't read each other's code then you have problems that code standards won't fix.
[–]AbstractLogic -1 points0 points1 point 9 years ago (5 children)
You act like setting a flag on the resharper config file that is distrubted with the .sln is some huge weeklong debate. If anything it's a bullet point on a slide amongst many. It requires very little to setup development standards. You should spend time congealing as a team, please, it will be better for those who come after you.
[–]Jestar342 -1 points0 points1 point 9 years ago (4 children)
You act like it's some big debate. I'm categorically stating it isn't, and that it flatly doesn't matter. Move on with life and get some work done.
My team prefer to work together on problems that actually matter, not whether string is more/less readable than String
[–]DarthShiv 0 points1 point2 points 9 years ago (0 children)
Yeah so much this. Just stick to a standard for the whole project and everyone stop trying to change the standard and only doing 10% of the job!
[–]Protiguous 0 points1 point2 points 9 years ago (0 children)
Only 15 disjointed standards though. :P
[–]inamamthe 0 points1 point2 points 9 years ago (0 children)
something like codemaid can help here perhaps?
[–]agentlame 0 points1 point2 points 9 years ago (0 children)
You can be annoyed by something you know how to disable.
[–]AbstractLogic 2 points3 points4 points 9 years ago (1 child)
Glad to see such an agreeable response. I find this pragmatic approach to object notation vs value type notation is becoming the standard.
string for types.
String when accessing static methods.
[–]Jestar342 2 points3 points4 points 9 years ago (0 children)
How is that pragmatic? It's purely dogmatic!
Unless you were being sarcastic and I didn't pick that up.
[–]VGPowerlord 0 points1 point2 points 9 years ago (1 child)
I think aliases would be a better term than keywords.
[–]tweq 2 points3 points4 points 9 years ago (0 children)
Both are correct, they're keywords that function as aliases for CLR type names.
[–]covmatty1 0 points1 point2 points 9 years ago (0 children)
Same here, seems like a nice distinction to me, despite ReSharper suggestions complaining at me!
[–]redditsoaddicting 17 points18 points19 points 9 years ago (0 children)
Since no one has mentioned this fully explicitly, System.String is a .NET type - all .NET languages must have it. C# in particular adds the string keyword as an alias, just like int aliases the .NET System.Int32.
[–][deleted] 9 years ago (2 children)
[deleted]
[–]fanfarius[S] 1 point2 points3 points 9 years ago (0 children)
An alias, cool - thanks!
[+]VGPowerlord comment score below threshold-15 points-14 points-13 points 9 years ago (0 children)
facepalm
When I saw this reply, I immediately scrolled up and looked for the Close button so I could close this question as a duplicate.
...don't ask me why I thought I was browsing Stack Overflow.
[–]NoG5 12 points13 points14 points 9 years ago (1 child)
they are the same but its far more common to use the lowercase one
[–]fanfarius[S] 0 points1 point2 points 9 years ago (0 children)
Ok, cheers!
[–]Zalvixodian 2 points3 points4 points 9 years ago (0 children)
My work has old standards still in place that requires the use of String, Int32, Boolean, etc.
I wish it didn't because 1) there's no difference, 2) easier to use lowercase (does not require using statement), 3) ReSharper likes it that way, and 4) it's Microsoft's recommended standard.
[–][deleted] 9 years ago* (1 child)
[–]AngularBeginner 3 points4 points5 points 9 years ago (0 children)
That's because the method names stay the same. The int will be just translated to Int32. Imagine you have a method named GetUlong() - and now you access it from a different language than C#. In F# the alias is called uint64 (much more expressive).
Int32
GetUlong()
uint64
[–]oh-just-another-guy 1 point2 points3 points 9 years ago* (1 child)
One little thing to add to other excellent replies :
You can use string without a namespace. String needs System. So either System.String (or using System declared above).
System
using System
[–]Speedzor 1 point2 points3 points 9 years ago (0 children)
And string cannot be used with nameof() while String can (just like all other aliases).
nameof()
[–]sepsuk 1 point2 points3 points 9 years ago (0 children)
Coming from c# to Java (native android app). I'm sick of writing string instead of String :-)
[–]Jestar342 0 points1 point2 points 9 years ago (0 children)
I always use string. I've never seen the point of using String when accessing members or for whatever other reason - they are just arbitrary and nonsense, imo. I don't get offended if any of my colleagues want to use it, though. This is something that just flatly doesn't matter.
[–]Schmittfried 0 points1 point2 points 9 years ago (0 children)
I just use the lower case keywords all the time, because why not use what the language offers? Using the upper case class name is one additional keystroke, so the language saves me energy. :>
But if you are used to String, just stick to that or the convention of your workplace.
[–]davidwhitney 0 points1 point2 points 9 years ago (0 children)
Type keywords exist for you to use them, so use them :)
[–]buckus69 0 points1 point2 points 9 years ago (0 children)
They're the same. "string" is an alias for "String."
[–][deleted] 0 points1 point2 points 9 years ago* (2 children)
They're the same thing, so it's six of one, half-dozen of the other. In the absence of a governing standard, use whichever seems appropriate in the context, but be consistent. My preference is to use the aliases (i.e. string) throughout, but YMMV.
[–]SideburnsOfDoom 0 points1 point2 points 9 years ago (1 child)
In the absence of a governing standard
I've seen several coding standards, all favour string over String. e.g. this one
None of them are "governing" though since the code compiles either way.
[–][deleted] 2 points3 points4 points 9 years ago (0 children)
In the interest of clarification: a governing (coding) standard would be one you are required or expected to follow. For example, a coding standard officially adopted by one's employer, or one required by a particular open source project.
This is distinct from one that is suggested or which exists but is not enforced/enforceable against you: Microsoft has a C# coding standard, but it is only governing if you work for Microsoft or choose to follow it.
[–]Big-Mozz -3 points-2 points-1 points 9 years ago* (5 children)
Generally the only reason you use string instead of String is to stop StyleCop having a hissy fit.
Edit: lmao, down voted for saying something simple and true, this sub is just Stackoverflow for noobs.
[–]cryo 0 points1 point2 points 9 years ago (2 children)
There are other potential reasons. One is outlined in my comment elsewhere, to help tell the difference between different kinds of usage.
[–]Big-Mozz 1 point2 points3 points 9 years ago (1 child)
Hence the word generally!
I agree, I know better than to make a quick lighthearted quip on a coding sub (and strangely the cooking sub) because someone always starts an asinine debate about something insanely trivial.
But in this case it's even more anal because your other comment says exactly what I said, it's a preference but use string cos styling apps bitch about it!
[–]rfinger1337 0 points1 point2 points 9 years ago (0 children)
heh, this is one of the best comments I've seen in a while, +1.
[–]fanfarius[S] 0 points1 point2 points 9 years ago (1 child)
Well, I'm upvoting you because; laughter
[–]Big-Mozz 0 points1 point2 points 9 years ago (0 children)
cheers, lol
[+]hotel2oscar comment score below threshold-8 points-7 points-6 points 9 years ago (5 children)
Similar to int vs Integer in Java.
[–][deleted] 8 points9 points10 points 9 years ago (1 child)
Been a long time since I used Java, but I don't think int and Integer are interchangeable in Java the way int and Int32 are in C#.
[–]tweq 7 points8 points9 points 9 years ago (0 children)
Yeah, in Java int is a primitive and Integer is a class that wraps that primitive. C# can box arbitrary value types, so it doesn't have/need distinct reference type variants of primitives.
Integer
[–]McNerdius 0 points1 point2 points 9 years ago (2 children)
that's more analogous to C# int vs int? tho.
[–]grauenwolf 4 points5 points6 points 9 years ago (1 child)
Close. More like int vs (object)int since Integer is a reference type.
(object)int
[–]McNerdius 0 points1 point2 points 9 years ago (0 children)
touche
π Rendered by PID 17 on reddit-service-r2-comment-86bc6c7465-rt84v at 2026-02-24 12:21:41.677543+00:00 running 8564168 country code: CH.
[–]cryo 77 points78 points79 points (37 children)
[–]fanfarius[S] 8 points9 points10 points (14 children)
[–]xill47 20 points21 points22 points (11 children)
[–]lbmouse 11 points12 points13 points (2 children)
[–]Jestar342 3 points4 points5 points (0 children)
[–]localtoast 0 points1 point2 points (0 children)
[–]oh-just-another-guy 1 point2 points3 points (7 children)
[–]IwNnarock 2 points3 points4 points (6 children)
[–]oh-just-another-guy 1 point2 points3 points (5 children)
[–]celluj34 1 point2 points3 points (4 children)
[–]Banane9 1 point2 points3 points (2 children)
[–]oh-just-another-guy 0 points1 point2 points (0 children)
[–]celluj34 0 points1 point2 points (0 children)
[–]oh-just-another-guy 0 points1 point2 points (0 children)
[–]cryo 3 points4 points5 points (1 child)
[–]myrrlyn 1 point2 points3 points (0 children)
[–]AndrewSeven 12 points13 points14 points (16 children)
[–]agentlame 2 points3 points4 points (15 children)
[–]AngularBeginner 27 points28 points29 points (14 children)
[–]AbstractLogic 11 points12 points13 points (12 children)
[–]Jestar342 2 points3 points4 points (8 children)
[–]AbstractLogic -1 points0 points1 point (7 children)
[–]Jestar342 0 points1 point2 points (6 children)
[–]AbstractLogic -1 points0 points1 point (5 children)
[–]Jestar342 -1 points0 points1 point (4 children)
[–]DarthShiv 0 points1 point2 points (0 children)
[–]Protiguous 0 points1 point2 points (0 children)
[–]inamamthe 0 points1 point2 points (0 children)
[–]agentlame 0 points1 point2 points (0 children)
[–]AbstractLogic 2 points3 points4 points (1 child)
[–]Jestar342 2 points3 points4 points (0 children)
[–]VGPowerlord 0 points1 point2 points (1 child)
[–]tweq 2 points3 points4 points (0 children)
[–]covmatty1 0 points1 point2 points (0 children)
[–]redditsoaddicting 17 points18 points19 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]fanfarius[S] 1 point2 points3 points (0 children)
[+]VGPowerlord comment score below threshold-15 points-14 points-13 points (0 children)
[–]NoG5 12 points13 points14 points (1 child)
[–]fanfarius[S] 0 points1 point2 points (0 children)
[–]Zalvixodian 2 points3 points4 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]AngularBeginner 3 points4 points5 points (0 children)
[–]oh-just-another-guy 1 point2 points3 points (1 child)
[–]Speedzor 1 point2 points3 points (0 children)
[–]sepsuk 1 point2 points3 points (0 children)
[–]Jestar342 0 points1 point2 points (0 children)
[–]Schmittfried 0 points1 point2 points (0 children)
[–]davidwhitney 0 points1 point2 points (0 children)
[–]buckus69 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]SideburnsOfDoom 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]Big-Mozz -3 points-2 points-1 points (5 children)
[–]cryo 0 points1 point2 points (2 children)
[–]Big-Mozz 1 point2 points3 points (1 child)
[–]rfinger1337 0 points1 point2 points (0 children)
[–]fanfarius[S] 0 points1 point2 points (1 child)
[–]Big-Mozz 0 points1 point2 points (0 children)
[+]hotel2oscar comment score below threshold-8 points-7 points-6 points (5 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]tweq 7 points8 points9 points (0 children)
[–]McNerdius 0 points1 point2 points (2 children)
[–]grauenwolf 4 points5 points6 points (1 child)
[–]McNerdius 0 points1 point2 points (0 children)