[Solved] How can i find all the times between two given dates and time? [closed]

[ad_1] Gee, sometimes its fun to overengineer things. There is an Aggregate function which turns a list into a scalar value – lets create one that goes the other way public static class Extensions { public static IEnumerable<T> Explode<T>(this T value, Func<T,T> next, Func<T,bool> limit) { var n = value; while(!limit(n)) { yield return n; … Read more

[Solved] Split text file every 120,000 Lines?

[ad_1] Just another way using Enumerable.GroupBy and “integer division groups”: int batchSize = 120000; var fileGroups = File.ReadLines(path) .Select((line, index) => new { line, index }) .GroupBy(x => x.index / batchSize) .Select((group, index) => new { Path = Path.Combine(dir, string.Format(“FileName_{0}.txt”, index + 1)), Lines = group.Select(x => x.line) }); foreach (var file in fileGroups) File.WriteAllLines(file.Path, … Read more

[Solved] DBNull cast to (object) returns different value [closed]

[ad_1] I’m going to make a few assumptions, but I think I know what’s going on. municipio is probably an empty string. It is not null. In that case, municipio ?? (object)DBNull.Value will be an empty string, not null. However, municipio.Length > 0 ? municipio : (object)DBNull.Value has a value of DBNull.Value, which will generate … Read more

[Solved] Re-casting c# variables with a different class

[ad_1] Couldn’t you refactor it so that you have a generic method that takes a WebResponse? public T Deserialize<T>(WebResponse response) where T: new() // ensure that any type of T used has a parameterless constructor { string r = “”; using (StreamReader sr = new StreamReader(res.GetResponseStream())) { r = sr.ReadToEnd(); } JavaScriptSerializer js = new … Read more

[Solved] Remove space left after console scrollbars in C#

[ad_1] Finally, after a lot of head-scratching, I think I’ve solved this issue. Firstly, I had to add some additional WinAPI methods: [DllImport(“kernel32.dll”, SetLastError = true)] private static extern IntPtr GetStdHandle(int nStdHandle); [DllImport(“kernel32.dll”, SetLastError = true)] private static extern bool GetConsoleScreenBufferInfoEx( IntPtr hConsoleOutput, ref ConsoleScreenBufferInfoEx ConsoleScreenBufferInfo); [DllImport(“kernel32.dll”, SetLastError = true)] private static extern bool SetConsoleScreenBufferInfoEx( … Read more

[Solved] Trying to show a Windows Form using a DLL that is imported at the runtime in a console application

[ad_1] The problem is that Activator.CreateInstance does not return ExpandObject (dynamic). You should run test() by reflection, like this : foreach (Type type in DLL.GetExportedTypes()) { dynamic c = Activator.CreateInstance(type); MethodInfo methodInfo = type.GetMethod(“test”); methodInfo.Invoke(c , null); } 2 [ad_2] solved Trying to show a Windows Form using a DLL that is imported at the … Read more

[Solved] How can i make that the lines in richTextBox1 will start from the right to the left?

[ad_1] Refer to the documentation on SelectionAlignment property: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionalignment%28v=VS.100%29.aspx Use the above (in your scenario) like so: richTextBox1.SelectAll(); richTextBox1.SelectionAlignment = HorizontalAlignment.Right; [ad_2] solved How can i make that the lines in richTextBox1 will start from the right to the left?

[Solved] How to search a given word in word file by C# [closed]

[ad_1] If you are using the Aspose library as stated in your comment you can achieve this through a customised implementation of the IReplacingCallback interface. bool IsContain(string word, string filePath) { Document doc = new Document(filePath); OccurrencesCounter counter = new OccurrencesCounter(); doc.Range.Replace(new Regex(word), counter, false); return counter.Occurrences > 0; } private class OccurrencesCounter : IReplacingCallback … Read more