Categories > Coding > C# >

Welp me optimize terrible code

Posts: 0

Threads: 0

Joined: ?

Reputation:

Posted

https://cdn.discordapp.com/attachments/986313395882037258/988504638066147389/unknown.png

how optimize

  • 0

Posts: 2014

Threads: 198

Joined: Apr, 2021

Reputation: 16

Replied

Can't you just add

using Microsoft.Win32;

 

And then do the OpenFileDialog without the shortcut?

That kinda makes the code bad.

  • 0

Random quote here...

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

 HOLY THAT REDUCED RAM USAGE BY 40% 

THANKS @VoidableMethod

  • 0

Posts: 1479

Threads: 95

Joined: Oct, 2019

Reputation: 103

Replied

var FileOpen = new OpenFileDialog()
{
      Filter = "*Txt (*txt)|*.txt|Lua (*lua)|*.lua",
      /* Do Other Properties Like Starting Dir And Stuff */
};
Editor.Text = File.ReadAllText(FileOpen.FileName);

 

  • 0

Posts: 197

Threads: 10

Joined: Feb, 2021

Reputation: 9

Replied

Uh so if you use avalonedit it has built in load function which u can use.

Sorry if im wrong, i havent touch wpf/c# in ages lol + i write this without ide

Also make sure you using the win32 one

var FileDialog = new OpenFileDialog()
{
    Title = "Open File",
    Filter = "*Txt (*txt)|*.txt|Lua (*lua)|*.lua"
};

if (FileDialog.ShowDialog().GetValueOrDefault())
    Editor.Load(FileDialog.FileName);
  • 0

Im netral, not evil, not too kind either.

tar

CoolNickname

Posts: 142

Threads: 15

Joined: Jul, 2021

Reputation: 1

Replied

Just dont create a OpenFileDialog everytime, create once and reuse it

and " == true"💀

  • 0

https://imgur.com/a/oOomuUo

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )