Luna
Luna
CC#
Created by Luna on 6/4/2024 in #help
✅Refactor C# code
guys my code works, but i'm doubting that i made the most performant way to do it
public struct Proc
{
public string Name;
public int ID;
public string? Owner;
}
....................
public static void SaveAppsList()
{
if (File.Exists(FILE_PATH)) File.Delete(FILE_PATH);

using StreamWriter writer = new(FILE_PATH);
foreach (Proc item in ListOfProcs)
writer.WriteLine($"{item.ID}^{item.Name}^{item.Owner}");
}
public static void LoadAppsList()
{
if (!File.Exists(FILE_PATH)) return;
string readText = File.ReadAllText(FILE_PATH);

if (readText.Trim() == string.Empty) return;

readText = readText.Replace("\r\n", "\n");
List<string> lines = [.. readText.Split('\n')];
foreach (string line in lines)
{
if (line.Trim() == string.Empty) continue;
string[] processInfo = line.Split('^');
Proc proc = new()
{
ID = int.Parse(processInfo[0]),
Name = processInfo[1],
Owner = processInfo[2]
};
ListOfProcs.Add(proc);
}
}
public struct Proc
{
public string Name;
public int ID;
public string? Owner;
}
....................
public static void SaveAppsList()
{
if (File.Exists(FILE_PATH)) File.Delete(FILE_PATH);

using StreamWriter writer = new(FILE_PATH);
foreach (Proc item in ListOfProcs)
writer.WriteLine($"{item.ID}^{item.Name}^{item.Owner}");
}
public static void LoadAppsList()
{
if (!File.Exists(FILE_PATH)) return;
string readText = File.ReadAllText(FILE_PATH);

if (readText.Trim() == string.Empty) return;

readText = readText.Replace("\r\n", "\n");
List<string> lines = [.. readText.Split('\n')];
foreach (string line in lines)
{
if (line.Trim() == string.Empty) continue;
string[] processInfo = line.Split('^');
Proc proc = new()
{
ID = int.Parse(processInfo[0]),
Name = processInfo[1],
Owner = processInfo[2]
};
ListOfProcs.Add(proc);
}
}
btw, i hate my own code, i know i can do better, but idk how
11 replies
CC#
Created by Luna on 5/24/2024 in #help
✅ Detect the user name who started the process
No description
15 replies
CC#
Created by Luna on 7/3/2023 in #help
✅Modifying visual elements created in runtime
i'll send a snippet of my code
void x(){
TabPage tp = new TabPage("example");
TextBox tb = new TextBox();
tb.Text = "wasd";
tb.Dock = DockSytle.Fill;
tp.Controls.Add(tb);

tabControl1.TabPages.Add(tp);
}

void y(){
// how can i edit tb in this function
}
void x(){
TabPage tp = new TabPage("example");
TextBox tb = new TextBox();
tb.Text = "wasd";
tb.Dock = DockSytle.Fill;
tp.Controls.Add(tb);

tabControl1.TabPages.Add(tp);
}

void y(){
// how can i edit tb in this function
}
12 replies
CC#
Created by Luna on 6/2/2023 in #help
❔ Color of a progressBar in Windows Forms
I have a progress bar in my windows forms and when i change the color (ForeColor, BackColor) in the proprieties menu, and i tried in the runtime too but didnt work in both ways
7 replies
CC#
Created by Luna on 4/23/2023 in #help
❔ Getting a value from an class in a list that is an attribute from another class
This code is an exmaple
class a{
.............
public List<b> listB { get; set; }
.............
}

public class b{
public int number { get; set; }
public string text { get; set; }
}
class a{
.............
public List<b> listB { get; set; }
.............
}

public class b{
public int number { get; set; }
public string text { get; set; }
}
I have an instance of class a, and I want to get the string text from 1 of the objects in the list List<b> listB how can I do that? I'm new to OOP and making this project to get better
7 replies