[Solved] Error not all code paths return a value?

public Int64 id(string fd, string tb) { Int64 I = 0; if (con.State == ConnectionState.Open) { con.Close(); else { con.Open(); } SqlCommand cmd = new SqlCommand(“SELECT MAX (” + fd + “) FROM ” + tb + “”, con); cmd.CommandType = CommandType.Text; if (con.State == ConnectionState.Closed) { con.Open(); I = Convert.ToInt64((cmd.ExecuteScalar().Equals(DBNull.Value) ? 0 : cmd.ExecuteScalar())) … Read more

[Solved] C# custom add in a List

I would use a HashSet<string> in this case: var files = new HashSet<string> { “file0”, “file1”, “file2”, “file3” }; string originalFile = “file0″; string file = originalFile; int counter = 0; while (!files.Add(file)) { file = $”{originalFile}({++counter})”; } If you have to use a list and the result should also be one, you can still … Read more

[Solved] Prevent duplicates from array, based on condition [closed]

You can write your own extension method that works like the built-in LINQ methods: public static class Extensions { public static IEnumerable<T> DistinctWhere<T>(this IEnumerable<T> input, Func<T,bool> predicate) { HashSet<T> hashset = new HashSet<T>(); foreach(T item in input) { if(!predicate(item)) { yield return item; continue; } if(!hashset.Contains(item)) { hashset.Add(item); yield return item; } } } } … Read more

[Solved] C# Asynchronous Server Sockets – Thread-Safety/Performance (MMO Gaming) [closed]

The first thing I want to mention, since I believe it is answers the root of your question, is that your performance (latency, concurrent connection capacity, etc) is going to be largely defined by the hardware you are running this software on and the network performance for each specific client. Software can improve some things … Read more

[Solved] Length of string in String.Format()

That is so totally not a string.format issue that it is not funny. Please consider doing a little basic debugging yourself. Values (abc,efd,gr,y,t,ui,u,re,re This is not valid SQL. See, string values have to be in paranthesis of some sort (‘abc’ instad of abc). Simply speaking your (btw, the old string.format syntax is hard to read … Read more

[Solved] C# Method makes forms dynamically via string

Here’s a simple example using the Reflection approach: private void button1_Click(object sender, EventArgs e) { Form f2 = TryGetFormByName(“Form2”); if (f2 != null) { f2.Show(); } } public Form TryGetFormByName(string formName) { var formType = System.Reflection.Assembly.GetExecutingAssembly().GetTypes() .Where(T => (T.BaseType == typeof(Form)) && (T.Name == formName)) .FirstOrDefault(); return formType == null ? null : (Form)Activator.CreateInstance(formType); } … Read more

[Solved] How to check PowerShell disable by group policy using C#

There is a limitation called ExecutionPolicy, setting, which can prevent from running scripts from files. From C#, you can create an instance of InitialSessionState with ExecutionPolicy = ByPass and create Powershell with this initial session state. Then try to run your script file with Invoke-Command -FilePath command. solved How to check PowerShell disable by group … Read more

[Solved] Compile c code in c# project

Process.Start will let you run any application including GCC (or any other compiler/make utility) and pass arguments. Process.Start(“gcc.exe”, “my.c”); You probably need more command line options than just file name (i.e. output/include folder locations) and may need to specify path to compiler if it is not already available in the PATH environment variable. 3 solved … Read more