|
You really need some mental gymnastic to read my message and think that I'm trying to diminish you.
I am not the one inserting some nationality (Mexican in your case) followed by a derogatory term (hobo) to say something is bad.
I was not offended, I just said that the message could have been answered without inserting any nationality. I don't get offended by random people on Internet, I would be a very bitter person if I did. But I also tend to think that bigots are usually not the smartest people in the planet.
That being said, I'm not interested in wasting more time responding to someone that is showing your kind of behaviour, I have better things to do with my life.
Hasta la vista Thornik.
|
|
|
|
|
DataRows are related to the tabular nature of a DataGridView and don't have to be backed by a database. DataRecords are related to actual database records.
|
|
|
|
|
obermd wrote: DataRecords are related to actual database records.
Not necessarily.
|
|
|
|
|
A DataReader is "forward reading" only. "Rows" have never been part of the nomenclature associated with sequential data sets (i.e. records; record set).
Rows can be usually be [indexed]; "records" rarely, unless they're fixed length (it's usually a positioning; then a read).
DataReader.HasRows throws it all out the window; of course.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
OK, so after my earlier post, I found that I was compiling with C# 6 turned on without realizing it.
I prefer to use new features of C# only if they offer me something useful. I use only a few features of C# 3, and no newer features than that, so I want my code to compile with C# 3 selected, but I hadn't been bothering to specify it, I had left it set to the default (my fault of course).
So yesterday I spent some time ensuring that my libraries and utilities will compile with C# 3.
And BOOM! one of my recent utilities complained:
error CS0840: '[REDACTED].CommonBase.ScriptXML.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
and
error CS8026: Feature 'readonly automatically implemented properties' is not available in C# 3. Please use language version 6 or greater.
(Messages from two versions of CSC.EXE . I'm not sure which is the more helpful.)
It turns out that a few months back, I had made a copy/paste error. I had intended to write:
public System.Xml.XmlNode ScriptXML { get ; private set ; }
but, because I had copied:
System.Xml.XmlNode ScriptXML { get ; }
from an Interface definition, I wound up with:
public System.Xml.XmlNode ScriptXML { get ; }
I had forgotten to add the private set ; (or do I want it protected?) and the compiler (set to C# 6) was fine with it! !
Yeah, OK, so it's not actually a bug, but it's a coding error and I wish I had been alerted to it when I first wrote it.
Going forward, I am specifying /langversion:3 until I find a useful feature of some future version.
Bonus: My work laptop has these two versions of CSC.EXE:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Supports up to C# 5
C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe Supports up to C# 6
and, of course, I had been using the newer version (as you do). I expect the newer version was installed in the past month.
But I found that utilities compiled with the newer version won't run on the servers, so I had to revert to using the older version when I compile on the command line, which is the norm for my utilities.
Yes, I do use Visual Studio (2015) on occasion, but not for making release builds of command-line utilities to deploy to the servers.
|
|
|
|
|
PIEBALDconsult wrote: it's a coding error
That depends on your intention.
If you wanted a property which could be modified by any code within your class, then yes.
If you wanted a true "read-only" property, which can only be initialized in the constructor or an initializer, then omitting the private set; is perfectly correct.
public class Foo
{
public int Bar { get; private set; }
public int Baz { get; }
public Foo(int bar, int baz)
{
Bar = bar;
Baz = baz;
}
public void Groot()
{
Bar = 42;
Baz = 42;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: could be modified by any code within your class
Yes. Even though I don't intend to change it. I prefer to leave that option open, possibly even making it protected instead.
Richard Deeming wrote: can only be initialized in the constructor
No. I prefer not to tie my hands that tightly. And I didn't realize that was the implication. I do occasionally make a readonly field though.
That "feature" may be good, but the implementation is not -- adding a limitation by not writing something.
|
|
|
|
|
That "feature" may be good, but the implementation is not -- adding a limitation by not writing something.
Say what? You are not "adding a limitation". You are not adding a feature (by not writing something). Or, written in the positive, You need to write something to add the capability. That's perfectly natural and correct.
Truth,
James
modified 1-Sep-22 9:08am.
|
|
|
|
|
I was just sure this was going to be about how sometime readonly isn't really readonly.
|
|
|
|
|
Command line utilities should be written in notepad and compiled with csc.exe.
|
|
|
|
|
Yes, which is what I do... as far as you know . (I actually wrote my own simple IDE.)
I don't like that notepad can't be flexible on TABs. I do use it for XML though.
|
|
|
|
|
In my opinion... .net should never have been released to the public with such inconsistencies as these.
System.DateTime.UtcNow .ToString ( "hh:mm:ss" ) ;
System.DateTime.UtcNow.TimeOfDay.ToString ( "hh\\:mm\\:ss" ) ;
new System.ArgumentException ( message , paramName ) ;
new System.ArgumentNullException ( paramName , message ) ;
|
|
|
|
|
Them's a beatin'.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
|
|
|
|
|
I'm guessing it has to do with people's obsessions about breaking changes.
|
|
|
|
|
That's why they can't fix it now, but it doesn't explain how things got that way to begin with, from v1 and earlier.
|
|
|
|
|
From v1? Gee. Maybe there were bun fights over the interface.
|
|
|
|
|
They probably copied it from Java and had to swap the order to avoid copyright infringement.
Before the judge:
See Java has its parameters in the same order for both. DotNet 1.0 is different.
|
|
|
|
|
The DateTime vs TimeSpan is more insidious than you think. DateTime.UtcNow.TimeOfDay.ToString("hh\\:mm\\:ss") will always use ":" as the separator, whereas DateTime.UtcNow.ToString("hh:mm:ss") will use the current culture's time separator. Whilst the default seems to use ":" consistently, I believe the user can override this in the OS settings.
var format = new DateTimeFormatInfo { TimeSeparator = "#" };
DateTime.UtcNow.ToString("hh:mm:ss", format);
DateTime.UtcNow.TimeOfDay.ToString("hh\\:mm\\:ss", format);
The argument exception one is annoying, but I can sort-of understand how it came to be. With an ArgumentNullException , there's an obvious default error message, and the main thing you care about is the name of the argument which was null . But with an ArgumentException , there's no obvious default error message, and the error could be caused by a combination of parameters, so the message is the main thing, and the parameter name is optional.
Since C# 4 introduced named parameters, you can use them to make the invocations consistent:
new ArgumentException(paramName: nameof(foo), message: "Bar");
new ArgumentNullException(paramName: nameof(foo), message: "Bar");
NB: Starting with .NET 6, the recommendation is to use ArgumentNullException.ThrowIfNull(parameter); instead of if (parameter is null) throw new ArgumentNullException(nameof(parameter)); :
ArgumentNullException.ThrowIfNull Method (System) | Microsoft Docs[^]
Introduce static methods to allocate and throw key exception types. · Issue #48573 · dotnet/runtime · GitHub[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't use .net 6 .
How would I specify the message though?
Edit: In fact I don't use any features of C# 4 either. And it may be that the only features I use of C# 3 are Extension Method, Collection Initializer, and Object Initializer.
I just ran through some of my libraries, seeing which require C# 3. Most do, but one will actually compile with C# 2.
And I had actually forgotten about Collection Initializer until this week -- I used it in two places in a piece of code I wrote in 2014, to initialize a Dictionary.
Last week I wrote some code which used a Dictionary Initializer, not realizing it is a C# 6 feature, and then rewrote it as a Collection Initializer when I found out.
In the code I am working on, the Dictionary Initializer provides no benefit over the Collection Initializer.
modified 27-Aug-22 13:26pm.
|
|
|
|
|
You wouldn't; the ThrowIfNull method always uses the default error message, which leads to more consistent errors.
You could override the parameter name, but it's best to let the compiler fill it in using the [CallerArgumentExpression] attribute.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Seems pointless anyway. Why would I want a "default error message"? Or, if I do, I'd make that an inner exception and provide a meaningful message in the main exception.
So far I have found no useful features of C# 6... except...
I just found that "dictionary initializer" is a C# 6 feature and I have been toying with that for a week or so now. Why didn't this exist since the advent of initializers?
I also just dabbled with string interpolation -- which I heard about, but hadn't bothered with -- and, as expected, it provides no benefit to me. It works only with string literals, and most format strings I use are not literals. It looks like it would lead to bad practices. In particular, how do you use string interpolation with globalization?
Anyway, now that I know that I am using a v6 compiler, I can see if that's why my recent builds refuse to execute on the servers. I'll specify v4 and see if they succeed then.
Edit: In case anyone is curious. Yes, once I rebuilt with an earlier compiler (v5), I was able to run the utility on the server. I am not in control of what versions of things (e.g. .net) are installed on my laptop and the servers, but it's never the latest version.
modified 27-Aug-22 13:27pm.
|
|
|
|
|
Aren't there similar quirks with the DateFormat?
And what about NumberFormat (like decimal separator etc.)?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
I think so. Plus in the past I've run into issues with other limitations on what can be specified in format strings.
Which led to this : ApplyFormat[^]
And this week I've been working on another formatter, kinda sorta similar to string interpolation, but not really.
|
|
|
|
|
How much money should they spend, in your opinion, to have parameters in the same order, even if it doesn't make sense?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
My programming career has been blessed by an affair or two with TECO the text editor.
Browsing around I can find very few examples of TECO code. So I decided to provide some for you.
Wait, if you dig hard enough you can always find TECO code by
guys like Stanley Rabinowtiz but what about every day, run of the mill
TECO macros?
For starters see DATE. Enjoy!
If you spot a bug then please submit a PR.
Dang! My '58 Renault Dauphine has another flat tire.
|
|
|
|