Talk:C Sharp syntax
![]() | This article is rated B-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||
|
|
Generics
[edit]Quote from the article:
The compiler will automatically replace every T in the code with the type you want to replace it with.
.NET parameterized types are instantiated at runtime rather than by the compiler
Done. Feel free to point out any more mistakes Aly89 (talk) 23:27, 4 November 2008 (UTC)
3.0
[edit]- From article:
This article contains new features of the upcoming C# 3.0. These features are not yet officially released.
Since C# 3.0 has been released already, this paragraph needs to be updated. 88.131.91.2 (talk) 11:40, 19 January 2009 (UTC)
Draft
[edit]Recently I've been writing a draft for this article. The purpose is to re-write the article to make it an even better one.
If you want to read it or perhaps edit it you'll find it here: User:Sundström/Drafts/C_Sharp_syntax
Contributions are needed and comments are appreciated. Robert Sundström (talk) 11:37, 24 July 2009 (UTC)
Merge proposal
[edit]I have not got any responses from any other user. Do anyone think that we could merge this article with the draft. Is that okay? Robert Sundström (talk) 21:44, 3 August 2009 (UTC)
- I think that this article has been abandonned and I have taken the initiative of merging these articles, Robert Sundström (talk) 10:36, 28 August 2009 (UTC)
I believe that the articles are well enough that they should be merged --Azatos (talk) 01:58, 26 September 2009 (UTC)
Syncronization
[edit]The article contains no information on the lock keyword. OrangeDog (talk • edits) 22:18, 29 September 2009 (UTC)
You
[edit]The use of "you" (i.e., first person voice) needs to be eliminated from this article. For example, "You can assign a value to a variable" should be rewritten as "A value can be assigned to a variable". — Loadmaster (talk) 23:48, 13 November 2009 (UTC)
Pointer syntax
[edit]In the pointers example, shouldn't the second line read:
Console.WriteLine("Value of b: {0}. pointed by b: {1}", b, *b);
(I didn't edit myself since I don't know C♯; but the code doesn't correlate with the comment about both lines producing the same value according to C syntax.) Diggory Hardy (talk) 18:19, 18 November 2009 (UTC)
LINQ Syntax
[edit]The article states rather vaguely that the reason 'from' comes before 'select' in the query syntax is "because it seems more natural writing like this in C#."
Now, I've read or heard (can't remember source which is why I didn't edit myself) that the reason for this is simply because IntelliSense would not work unless 'from' was first. Before the 'from' is entered, the editor cannot know the type of the item and cannot assist with popups etc. Can anyone confirm this? --Isaksavo (talk) 17:39, 18 December 2009 (UTC)
- The developers behind the LINQ syntax said that it is more convenient for a C-programmer to write a query this way. Correct me if I am wrong because it has been a while since I actually watched that talk. Maybe I should try to find it. --Robert Sundström (talk) 09:11, 5 April 2010 (UTC)
immutable strings?
[edit]C Sharp syntax#string class says:
- string class represents an immutable sequence of unicode characters.
Surely string objects can be changed? Mitch Ames (talk) 11:15, 4 April 2010 (UTC)
- No. When you perform an operation on a string you will get a new one. It is possible to use the StringBuilder class but the actual type System.String is immutable. Robert Sundström (talk) 09:03, 5 April 2010 (UTC)
- OK, thanks. I've removed the {{dubious}} tag. Mitch Ames (talk) 09:56, 20 April 2010 (UTC)
Covariance and contravariance
[edit][May 2010] I believe the example for contravariance could be improved. Currently, it seems oversimplified: I found it to be misleading at first, and fear that others could misinterpret it worse than I did.
From the article:
For contravariance, the existing interface
IComparer<T>
has been redefined as follows:public interface IComparer<in T> { int Compare(T x, T y); }Therefore, any class that implements
IComparer<Base>
for some classBase
is also considered to be compatible withIComparer<Derived>
for all classes and interfacesDerived
that are extended fromBase
. It makes it possible to write code such as:IComparer<object> objectComparer = GetComparer(); IComparer<string> stringComparer = objectComparer;
If one reads this snippet of code naively, the reader may falsely conclude that the second assignment (i.e. stringComparer = objectComparer
) is acceptable regardless of the kind of object that GetComparer()
has returned! In that case, the whole point of "what it does and why" would also be missed.
I am not the best qualified to rewrite this section; it should be done by a knowledgeable user of C# 4.0 who also has experience with 3.0 or 2.0. However, here are some recommendations:
- The contravariance section should illustrate a real usage.
- The section should be complete without being very long.
- The code in the earlier covariance example meets both of these criteria. One might actually expect to find a
PrintAll()
function, and it is reasonable to define it as working on any enumerable collection of objects, and later to want to call it on a list of strings. The example is complete enough to show what is going on.
- The example should also show 1-2 lines of erroneous usage.
- This helps many readers better understand the limits of what the example is trying to illustrate. (The covariance example could also benefit from such an addition.)
- The example should discuss or show what happens when the keyword
in
was not used.
- This helps complete the example and shows why the feature was added. (Again, the covariant example could benefit from a similar addition.)
Finally, instead of using IComparer<T>
, I propose the example should use either IComparable<T>
, or a set of generic delegate classes. Why IComparable<T>
? The reader need only understand the concept of comparability (i.e. ‹ › == !=, etc.) in order to grasp enough of the context to make valid assumptions. (With IComparer<T>
, the reader must have much more background knowledge in order to understand the context.)
If not IComparable<T>
, then why generic delegates? The code examples required to illustrate all of the bullet points above might be shorter or clearer. I'm really not sure.
-- Forbin1 (talk) 19:21, 27 May 2010 (UTC)
Error in continue statement code sample
[edit]The code sample for the continue statement has an error.
The while loop does : 'while (ch = GetChar())' Since ch and GetChar() are of type int, the type of the expression between the parentheses is int. C\# only accept booleans. The compiler reports the following error : "Cannot implicitly convert type 'int' to 'bool'" —Preceding unsigned comment added by 83.134.40.84 (talk) 08:31, 21 August 2010 (UTC)
- I've corrected the code
79.182.115.238 (talk) 20:11, 9 January 2014 (UTC)
Events
[edit]The code in the Events section would fail with NullReferenceException.
In the Click method, you should check that the event is not null, or initialize the event with anonymous method/lambda expression:
event MouseEventHandler OnClick = (s, e) => { };
———————
"An event requires an accompanied event handler that is made from a special delegate that in a platform specific library"
This is wrong. events can work with any delegate. There is only a convention to use delegates with two parameters: an object that would receive the object that raised the event, and another object that is inherited from "EventArgs" and would receive the event arguments.
It's not even platform specific, but each event declares which delegate it's using.
It's only by convention that programmers should use the "EventHandler" delegate for parameterless events, or the generic "EventHandler<TEventArgs>" delegate for events which needs parameters.
84.228.76.97 (talk) 09:13, 9 January 2014 (UTC)
External links modified
[edit]Hello fellow Wikipedians,
I have just modified one external link on C Sharp syntax. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
- Added archive https://web.archive.org/web/20100105210417/http://knowdotnet.com/articles/attributes.html to http://www.knowdotnet.com/articles/attributes.html
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template {{source check}}
(last update: 5 June 2024).
- If you have discovered URLs which were erroneously considered dead by the bot, you can report them with this tool.
- If you found an error with any archives or the URLs themselves, you can fix them with this tool.
Cheers.—InternetArchiveBot (Report bug) 20:12, 28 July 2017 (UTC)
Move discussion in progress
[edit]There is a move discussion in progress on Talk:C Sharp (programming language) which affects this page. Please participate on that page and not in this talk page section. Thank you. —RMCD bot 21:35, 23 August 2018 (UTC)