|
Thank you very much for your suggestion, I've been reading about SqLite, it seems like a good option, my concern would be when installing Sql Server is very complicated, I'll follow your suggestion and I'll iterate on other lighter banks.
a hug and stay with God.
|
|
|
|
|
You're welcome!
If you only need single user access to the DB, then SQLite is a very good option.
If you need multiuser access, then you need a server based DB like Sql Server or MySql - but both of those are complex to install and need planning or you will cause loads of problems you never intended to!
"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!
|
|
|
|
|
You need to be more clear about this "one line" you need to edit / delete. Where is it? Front. End. Middle? How do you identify it? Is there a key?
Yes, you can "change" text files. And, yes, text files can be used as a "backing store"; e.g. serializing and deserializing objects to XML, for example. The old "ini files" were all text files.
However, one usually "stages" the text file as a "string list" or perhaps a dictionary, updates it in there, then "serializes" it to a text file for saving ... using the users' local or "roaming" storage.
"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
|
|
|
|
|
Edilson Lemos 2021 wrote: because I think that when installing it will make the process easier
Right now you have created a solution and then you are asking questions about that.
I suspect you need to think through the problem, rephrase it to make it very clear, and then ask for ideas on how to solve that. No code, just the problem.
From the line above, to me, it suggests you might be looking to create a 'new' install of a product where data is required for the database as a new install. If so yes there are solutions for that.
|
|
|
|
|
write a c# 8 Core 7 example of InterFace and Abstract class:
namespace _07_08_2023_test
{
public interface IFace1
{
DateTime DTimeUTC { get; }
}
public interface IFace2
{
string FirstName { get; }
string LastName { get; }
}
public abstract class Abs1 : IFace1, IFace2
{
public DateTime DTimeUTC {get; } = DateTime.Now.ToUniversalTime();
public string FirstName { get; protected set; }
public string LastName { get; protected set; }
public string FullName
{
get => $"{FirstName} ... {LastName}";
}
}
public class StudentMess : Abs1
{
public StudentMess(string fname, string lname)
{
FirstName = fname;
LastName = lname;
}
}
} And, said new student says: "it compiles, and I can do this:"
private void Form1_Load(object sender, EventArgs e)
{
StudentMess smess = new StudentMess("new", "confused");
}
And, you shake your head.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Judging by your message here, and earlier posts, I guess that you're trying to figure out what problem is being solved by the new interface implementations capability being introduced in the language now. Would that be fair to say? If so, you aren't actually using that capability in your example. What am I missing here?
-- edited to add the word using
modified 9-Aug-23 6:58am.
|
|
|
|
|
Pete O'Hanlon wrote: what problem is being solved by the new interface implementations capability being introduced in the language now. Thanks, Pete
Yes, i am asking what advantages are being offered to make what, imho, is a classic pillar of modern programming a different construct. Pete O'Hanlon wrote: What am I missing here? i guess my "student mess" example did not convey the difficulty in getting a strategic sense of when to use Interface and Abstract.
bill is missing many things right now, including (too often) ability to concentrate, i apologize for my lack of thoroughness.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
So, the biggest advantage of the interface implementation is that it allows you to add features to an interface without breaking existing implementations. Imagine that you have the following interface:
public interface MyRestApi
{
string ApiName { get; set; }
int Version { get; set; }
string RequestBody { get; set; }
} Now, as an application API author, you have published this interface and your component uses it quite successfully; more importantly, you have shipped this out and 1/4 million happy customers are using your component and are supplying their own implementations of this API into your component. Let's say that you have decided that you want to upgrade your component and add a new feature to this interface; you have decided that it will support a check-sum. You don't want to upset those customers who are already using your component by breaking their build by adding a new property they have to supply. You don't want to stop those customers from having to change their code to use a version 2 of this API; which could be significant disruption. Finally, you want the customers to be able to use your upgraded capability, and adjust to supplying their own checksum implementation when they are ready. That's what this capability provides; you can upgrade the interface by supplying your own default implementation, satisfying the ability not to break things, and the consumer can upgrade the implementation if they want to later on. So, the next version of your component has this interface
public interface MyRestApi
{
string ApiName { get; set; }
int Version { get; set; }
string RequestBody { get; set; }
uint Checksum()
{
using CRC32 crc32 = new();
byte[] data = Encoding.UTF8.GetBytes(RequestBody);
byte[] hashBytes = crc32.ComputeHash(data);
return BitConverter.ToUInt32(hashBytes, 0);
}
} Now, I've just typed this code into the text window here so it may not be 100% correct, but this is one of the reasons for this capability.
modified 10-Aug-23 9:53am.
|
|
|
|
|
using C# 8 new Interface features:
public interface IExampleInterface
{
void DefaultMethod()
{
Console.WriteLine("This is the default implementation of DefaultMethod.");
}
static void StaticMethod()
{
Console.WriteLine("This is a static method in an interface.");
}
} And ... in C#9: Init-only setters; Target-typed new expressions ... in C#10: Record structs.
imho, Interface is becoming very different, and learning the strategic use of the new features much more difficult.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
I agree with your final statement. I would be interested in knowing what new devs, coming to .NET now, think of it.
|
|
|
|
|
Just to make things more confusing, a static interface member with a default implementation must be marked as virtual , otherwise you'll get a compiler error when you try to use it:
public interface IFoo
{
static void S() => Console.WriteLine("Default");
}
static void Test<T>() where T : IFoo
{
T.S();
} If you don't provide a default implementation, you have to mark it as abstract .
In order to provide its own implementation, a class has to declare the method as public , which doesn't match the interface declaration, leading to more confusion:
public interface IFoo
{
static virtual void S() => Console.WriteLine("Default");
}
public class Foo : IFoo
{
static void S() => Console.WriteLine("Overridden");
}
static void Test<T>() where T : IFoo
{
T.S();
}
Test<Foo>(); You can alleviate that by marking the interface method as public :
public interface IFoo
{
public static virtual void S() => Console.WriteLine("Default");
} But IMO, adding access modifiers to interface members goes against the "ethos" of interfaces. If I can see the interface, then I should be able to access all members of that interface, so they shouldn't need to be marked as public . And having some members protected or private just seems like nonsense!
And if that's still not confusing enough, the implementation of the static method cannot use the override modifier, even though it's required when you provide an implementation of a virtual / abstract method from a base class:
public class Foo : IFoo
{
public static override void StaticMethod() => Console.WriteLine("Overridden");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: adding access modifiers to interface members goes against the "ethos" of interfaces. "ethos" ... right word !
i am curious which versions of future C#/.NET your thorough review of future "features" are based on ...
aside: i am still hung-up on the fact that C# inner classes within outer classes "mean nothing" ... unless, of course you want to make them private and only use/manipulate then from within their containing classes ... i am probably still in recovery from 'Self in SmallTalk, "super" in Java ... my problem !
cheers, bill
`
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
|
Some more confusion for you from Reddit, relating to the older default interface implementation rather than the newer static interface members:
I had a question while reading the Microsoft docs on interfaces
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods#reabstraction[^]
In the docs, they give the example
interface IA
{
void M() { WriteLine("IA.M"); }
}
interface IB : IA
{
abstract void IA.M();
}
class C : IB { }
Which forces you to implement method M in class C . However, you can also define the interface IB this way, which also forces method M to be defined in class C .
interface IA
{
void M() { WriteLine("IA.M"); }
}
interface IB : IA
{
new void M();
}
class C : IB { }
I did notice there is a small difference, where since in the second example, interface IB is shadowing IA, the error message changes, but in practice, is there any difference between these two?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I would prefer the second one as it completely hides IA from C (which mostly I would want when I setting up like this). This also suggests me that the 1st implementation is for scenarios where you don't want to hide and be much more explicit about who is asking to implement (also IB is mostly playing middlemen for some reason known/unknown).
|
|
|
|
|
I'm populating a Datagriview from a text file with several lines with 15 numbers each, these numbers change every day, as well as the number of lines.
Ex:
*01 05 08 09 10 12 15 16 17 18 19 20 22 24 25
*02 07 08 09 10 11 15 16 17 18 20 21 22 24 25
*01 07 08 09 10 12 13 15 17 18 19 20 21 22 25
I also have an array that generates 15 random numbers between 01 and 25,
ex: 01 02 04 05 08 09 13 15 16 17 18 19 20 22 25
I need to count how many numbers in each line are repeated with the numbers in the array.
tenho seguinte codigo, mas não me traz um resultado satisfatório.
<pre> private IDictionary<int, int> GetResultFromTextFile(IEnumerable<int> src)
{
var filePath = @"C:\BoaSorte\Banco\testeResultado.txt";
var delimiter = new[] { ' ' };
var dict = File.ReadLines(filePath)
.Where(line => !string.IsNullOrEmpty(line))
.Aggregate(new Dictionary<int, int>(), (d, line) =>
{
var values = line
.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x));
var matchCount = values.Where(v => src.Contains(v)).Count();
if (matchCount <= 15)
{
if (d.ContainsKey(matchCount))
d[matchCount]++;
else
d[matchCount] = matchCount;
}
return d;
});
return dict;
}
<pre>private void button1_Click(object sender, EventArgs e)
{
int outVal;
if (UltimoResultado.Any(Acertos => !int.TryParse(Acertos.Text, out outVal)))
{
MessageBox.Show("Valores Invalidos...");
return;
}
var arr = UltimoResultado.Select(linha => int.Parse(linha.Text));
var result = GetResultFromTextFile(arr).ToList();
for (int i = 0; i < result.Count; i++)
{
dgHits.Rows[i].Cells["Acertos"].Value = result[i].ToString();
}
}
a picture of how i'm receiving
how am i receiving
how do i need it to appear
thank you in advance for any comments
modified 20-Aug-23 23:06pm.
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
"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!
|
|
|
|
|
Your code is storing the repeated counts as keys in the dictionary, which results in multiple repetitions being displayed in a single row in the DataGridView in your 'Acertos' cell.
You need to store the dictionary values to store the count of repetitions for each line, rather than the repeated count itself -
private IDictionary<int, int> GetResultFromTextFile(IEnumerable<int> src)
{
var filePath = @"C:\BoaSorte\Banco\testeResultado.txt";
var delimiter = new[] { ' ' };
var dict = File.ReadLines(filePath)
.Where(line => !string.IsNullOrEmpty(line))
.Aggregate(new Dictionary<int, int>(), (d, line) =>
{
var values = line
.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x));
var matchCount = values.Count(v => src.Contains(v));
if (d.ContainsKey(matchCount))
d[matchCount]++;
else
d[matchCount] = 1;
return d;
});
return dict;
}
private void button1_Click(object sender, EventArgs e)
{
int outVal;
if (UltimoResultado.Any(Acertos => !int.TryParse(Acertos.Text, out outVal)))
{
MessageBox.Show("Valores Invalidos...");
return;
}
var arr = UltimoResultado.Select(linha => int.Parse(linha.Text));
var result = GetResultFromTextFile(arr).ToList();
for (int i = 0; i < result.Count; i++)
{
dgHits.Rows[i].Cells["Acertos"].Value = result[i].Value.ToString();
}
}
|
|
|
|
|
hello André Oosthuizen, Muito Obrigado por responder meu tópico.
what is happening to me is that it returns the repeated numbers of the Array [ex: 13 hits, and the number of lines with 13 hits ex: 2]
I would like only the Hits to return, each one in its respective line as in the second image,
this code is returning the amount of line as n Hits,
if (d.ContainsKey(matchCount))
d[matchCount]++;
else
d[matchCount] = 1;
I need the opposite, the number of hits for each line (or Repeated from the array)
it's working, but the lines that have the same number of hits don't return anything
<pre lang="C#">if (matchCount <= 15) { d[matchCount] = matchCount; }
modified 9-Aug-23 21:14pm.
|
|
|
|
|
 I think I know what you need, try the following code. I did not test it so you might need to change it to do exactly as you require -
private IDictionary<int, int> GetResultFromTextFile(IEnumerable<int> src)
{
var filePath = @"C:\BoaSorte\Banco\testeResultado.txt";
var delimiter = new[] { ' ' };
var dict = new Dictionary<int, int>();
foreach (var line in File.ReadLines(filePath).Where(line => !string.IsNullOrEmpty(line)))
{
var values = line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x));
var matchCount = values.Count(v => src.Contains(v));
if (matchCount <= 15)
{
if (!dict.ContainsKey(matchCount))
{
dict[matchCount] = 0;
}
dict[matchCount]++;
}
}
return dict;
}
private void button1_Click(object sender, EventArgs e)
{
int outVal;
if (UltimoResultado.Any(Acertos => !int.TryParse(Acertos.Text, out outVal)))
{
MessageBox.Show("Valores Invalidos...");
return;
}
var arr = UltimoResultado.Select(linha => int.Parse(linha.Text));
var result = GetResultFromTextFile(arr).ToList();
for (int i = 0; i < result.Count; i++)
{
dgHits.Rows.Add();
dgHits.Rows[i].Cells["Acertos"].Value = result[i].Value.ToString();
}
}
|
|
|
|
|
Andre Oosthuizen wrote:
if (!dict.ContainsKey(matchCount))
{
dict[matchCount] = 0;
}
dict[matchCount]++; That checks whether the dictionary contains the key; sets the value if it doesn't; gets the value; then sets the value again.
It would be more efficient to use:
dict.TryGetValue(matchCount, out int existing);
dict[matchCount] = existing + 1; If the dictionary doesn't contain the key, the existing variable will be set to 0 .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
André Oosthuizen, thank you very much for your attention, I will try to explain myself better,
I need to show how many hits are in each line, comparing with the numbers generated in the array,
EX: line 1 --- 10 hits,
line2 --- 8 hits,
row 3 --- 10 hits,
line 4 --- 11 hits,
line 5 --- 11 hits,
row 6 --- 7 hits.
the code I have, shows me the total lines with 10 hits,
the total lines with 11 hits,
the total rows with 7 hits, Just exemplifying
*that's not what I need.
what i need each line to have the number of hits at the end of the line itself.
I'll leave an image to try to understand.
Exemple image
modified 10-Aug-23 17:45pm.
|
|
|
|
|
I solved my problem as follows
string[] lines = File.ReadAllLines(@"C:\BoaSorte\Banco\testeResultado.txt");
string[] line, contents, result;
int count;
result = textBox1.Text.Split();
for (int i = 0; i < lines.Length; i++)
{
contents = lines[i].Split(' ');
count = contents.Intersect(result).Count();
line = new string[16];
for (int j = 0; j < 15; j++)
line[j] = contents[j];
line[15] = count.ToString();
dgHits.Rows.Add(line);
}
Thanks for the help of André Oosthuizen and Richard Deeming
|
|
|
|
|
Only a pleasure, glad you found the solution!
|
|
|
|
|
I've been tasked with reading & writing file to/from sharepoint. I've never even seen Sharepoint before.
I have a Windows app that will load files from Sharepoint, run some processing, and write the results back out to Sharepoint. They have made me an admin on it so I can set things up.
I've been Googling, but all I get are snippets with little context.
I'm going to ask some stupid questions...
- How do I setup the location(s) I need?
- Are there actual folders I can read/write from? How do I reference them? Like a drive letter? Or do I need an API?
- Where do I go to get sharted doing this with C#?
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|