|
PIEBALDconsult wrote: typeof(T).GetFields is better than System.Enum.GetNames
Enum.GetNames calls typeof(T).GetEnumNames , which then calls typeof(T).GetFields , so there's not going to be a huge difference.
However, GetEnumNames sorts the names by the value of the enum member, so there may be a very small performance hit there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Right. Sorting is unnecessary as we're just adding them to a Dictionary anyway and losing the order.
Not a huge difference performance, particularly as it should happen only once per run and an enum should have few members to begin with.
My earlier comment on an "article" also pointed out that the Dictionary (ies) can be static because they don't change.
I'll also add though, that my implementation also supports having a DescriptionAttribute on each member and that can only be retrieved by retrieving the members (fields), not simply enumerating the names.
Plus... I allow finding an enum value by an abbreviated name, not just the full name, but that's not often useful.
|
|
|
|
|
How C# handles binary files?
I already know how to read binary files with the "ReadAllText" command.
|
|
|
|
|
Member 14773258 wrote: I already know how to read binary files with the "ReadAllText" command. Then, unfortunately, you do not know how to read binary files. If you read a binary file as text then it is very likely that the data will be corrupted as the system tries to interpret characters such as return (\r ) and line feed (\n ). To read binary files correctly you must read them in raw mode into arrays of pure bytes. From there you need to know the structure of the data in the files before you can do anything useful with it.
|
|
|
|
|
You very definitely don't read binary file data with ReadAllText - you need ReadAllBytes[^] which returns a byte[] instead of a string.
Strings are made of characters, which are generally variable length: they could be 8 bit, they could be 16 - and reading binary data as text is a very good way to corrupt it beyond hope of recovery.
This may help: ByteArrayBuilder - A StringBuilder for Bytes[^] it allows you to apply some "structure" to a binary file and read it in a "sensible" way. If nothing else, it shows one way to handle binary data files, but if your data files already exist and you must read them, then you will probably need to take a good hard look at the file format before you get started - there will be a structure applied to it, but what structure depends on the developer who produced them!
If you are to produce your own dtaa files, then it's probably a better idea to look at using JSON or even XML instead of binary data - it's much, much easier to handle I/O as both can "fill classes" for you when your read or write the data. Saves a whole load of work!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
how to create this program??
a program that will ask the user to enter positive number and loop/ continue until the user input a negative value and stops the loop.
The program will display
● The total number of positive numbers input
● The maximum (Highest) value
● The minimum (Lowest) value
● The equation
● And the average
Note:
● When the input is ZERO, the program will display a message that tells the user must input a positive or negative value, and ask the user to enter again a value
● ZERO will be discarded
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
First C# Program
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I'd use a Consol application. The only thing I don't understand is what displays "The equation" means?
|
|
|
|
|
I suspect 'equation' means sum. Probably a translation issue.
|
|
|
|
|
I want to make a server and client side WITSML (for Oil & Gas Wells Drilling Data Send/Receive). There are some SDKs here: (WITSML api library for .Net / C# client apps?). I surfed though the internet, but i have not been found any code example or guide to use them.
My Question:
==>.Are There any code example to develop a WITSML and/or WITS server and Client side software in C#?
Thank you in advance.
|
|
|
|
|
Member 13325846 wrote: Are There any code example If Google does not find any then you can assume probably not. It is always possible that you are the first to want to do this.
|
|
|
|
|
|
I have this code
public partial class TrimOptions : Form
{
public bool trimFirst { get; set; } = false;
public bool trimLast { get; set; } = false;
public bool ifBlank { get; set; } = true;
public TrimOptions()
{
InitializeComponent();
chkTrimFirst.DataBindings.Add(new Binding("Checked", trimFirst, null, false, DataSourceUpdateMode.OnPropertyChanged));
chkTrimLast.DataBindings.Add(new Binding("Checked", trimLast, null, false, DataSourceUpdateMode.OnPropertyChanged));
chkIfBlank.DataBindings.Add(new Binding("Checked", ifBlank, null, false, DataSourceUpdateMode.OnPropertyChanged));
} Whatever I set the properties to in code is reflected in the UI when the form is displayed. So far, so good. However, the user clicking the checkboxes does not set the properties, and setting the properties programmatically does not change the UI (nor the Checked property of the control).
I would like programmatic changes to the properties to update the UI, and I would like the user changing the UI to update the properties. How to do that?
modified 14-Feb-21 13:43pm.
|
|
|
|
|
|
Thank you!
chkTrimFirst.DataBindings.Add(new Binding("Checked", this, "trimFirst", false, DataSourceUpdateMode.OnPropertyChanged));
chkTrimLast.DataBindings.Add(new Binding("Checked", this, "trimLast", false, DataSourceUpdateMode.OnPropertyChanged));
chkIfBlank.DataBindings.Add(new Binding("Checked", this, "ifBlank", false, DataSourceUpdateMode.OnPropertyChanged)); This is working just fine now.
|
|
|
|
|
Excellent! I see you recognized "this" (the data source) as the form.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I am using following code to download file from FTP. I want to enhance this code with Auto Resume functionality in case of Internet disconnection. This code works perfect to download a file but doesn't auto resume. Please provide me C# source code to apply auto resume. My code supports bigger file also that is multiple GB download. Please review my code and please suggest how in my code I can integrate Resume.
\\\\\\\\\\\\\\\\\\\\ code
try
{
//Create FTP Request.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTPPath);
request.Method = WebRequestMethods.Ftp.DownloadFile;
//Enter FTP Server credentials.
request.Credentials = new NetworkCredential(FTPUser, FTPPassword);
request.UsePassive = true;
request.UseBinary = true;
request.EnableSsl = false;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
int length = 0;
int bytesToRead = 26214400;
byte[] buffer = new Byte[bytesToRead]; // Buffer to read bytes in chunk size specified above
long responseFileLength = this.FtpGetFileSize(FTPPath, FTPUser, FTPPassword); // Get the file size on the ftp
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Expires = -1;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + origionalFileName + "\"");
HttpContext.Current.Response.AddHeader("Content-Length", responseFileLength.ToString());
do
{
if (HttpContext.Current.Response.IsClientConnected)
{
length = stream.Read(buffer, 0, bytesToRead);
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
HttpContext.Current.Response.Flush();
buffer = new Byte[bytesToRead];
}
else
{
length = -1;
}
} while (length > 0); //Repeat until no data is read
IsDownloaded = true;
HttpContext.Current.Response.Clear();
}
}
catch (WebException ex)
{
}
|
|
|
|
|
|
You seem to have the wrong idea about this site, you may request help with a problem but supplying code is not what CP is about.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|
Kindly understand that I really can't figure out how to get this neural network concept to work as code. Anyway, has anyone figured out how to create the C# source code implementation for this?
https://imgur.com/qN1QLHe
|
|
|
|
|