some rando c sharp notes

rando notes

  • find .net version

dir /b /ad /o-n %systemroot%\Microsoft.NET\Framework\v?.*

many other ways

https://dotnetcoretutorials.com/2018/08/04/csv-parsing-in-net-core/

https://joshclose.github.io/CsvHelper/


calling functions

class ReturnTest
{
    static double CalculateArea(int r)
    {
        double area = r * r * Math.PI;
        return area;
    }

    static void Main()
    {
        int radius = 5;
        double result = CalculateArea(radius);
        Console.WriteLine("The area is {0:0.00}", result);

        // Keep the console open in debug mode.
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}
// Output: The area is 78.54

No secret keyword or design here. What happens is that each of these methods returns the instance of the TestServer (simply by returning this):

TestServer DoThis()
{
    // method code
    return this;
}

TestServer DoThat(string WithThisParameter)
{
    // method code
    return this;
}
And then you can do this:

var x = new TestServer();
x.DoThis().DoThat("my string").DoThis();
string newfolder = "c:\\TEMP\\bonk";
Console.WriteLine("creating folder "+ newfolder);
Directory.CreateDirectory(newfolder);

//  new file https://docs.microsoft.com/en-us/dotnet/core/api/system.io.file
string newfile = (newfolder+"\\bonk.md");
// newfile = Path.GetFullPath(newfile);
Console.Write("creating file "+newfile);
File.Create(newfile);

https://github.com/dotnet/docs/tree/master/samples/csharp/getting-started/console-teleprompter

https://blogs.msdn.microsoft.com/luisdem/2016/10/11/net-core-how-to-publish-a-self-contained-application-exe/


https://stackoverflow.com/questions/384743/how-to-quickly-code-and-run-small-c-sharp-code

The best suitable solution for me was using the C# Interactive-window. You can access it by opening it via View > Other Windows > C# Interactive, or by selecting some c# code and clicking on Execute in Interactive in the right-click context menu.

todo: snippets

  • ftp
  • csv by column name
  • web requests
  • file/folder crud
  • entity crud
  • mvc frameworks w/ basic crap built like customer / user auth management + form validation + crud models (django)
  • web front end to run back end (flask) process + output to web
  • web front end to run (flask) os.cmd() or equivalent

function wrappers

https://docs.microsoft.com/en-us/biztalk/core/how-to-set-deployment-properties-in-visual-studio


get self docs like sphinx

https://softwarerecs.stackexchange.com/questions/171/what-tool-can-generate-html-documentation-from-c-code-like-javadoc-can-do-for


c sharp compiled executable runs on multi platfom

using System;
using System.IO;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //  new directory https://docs.microsoft.com/en-us/dotnet/core/api/system.io.directory
            string newfolder = "c:\\TEMP\\bonk";
            Console.WriteLine("creating folder "+ newfolder);
            Directory.CreateDirectory(newfolder);

            //  new file https://docs.microsoft.com/en-us/dotnet/core/api/system.io.file
            string newfile = (newfolder+"\\bonk.md");
            // newfile = Path.GetFullPath(newfile);
            Console.Write("creating file "+newfile);
            File.Create(newfile);

            // new content in the file https://docs.microsoft.com/en-us/dotnet/core/api/system.io.filestream
            // string filecontents = @"hi there";
            // // Console.Write("writing "+filecontents+" to "+newfile);
            // File.WriteAllText("c:\\temp\\bonk\\bonk.md", filecontents);
        }
    }
}

open terminal

ctrl backtick to open terminal

open project

dotnet new

create dependancies

dotnet restore

run

dotnet run

set breakpoint

click by line number

debug

f5

files

http://stackoverflow.com/questions/802541/creating-an-empty-file-in-c-sharp

compile

dotnet publish

to run in command dotnet your.dll

compile exe

install build tools

https://www.microsoft.com/en-us/download/confirmation.aspx?id=48159

http://stackoverflow.com/questions/35544588/how-do-you-compile-a-console-application-with-vs-code-windows-platform

background tasks

Comments