stackoverflow1453

Programming&&Games&&Life

Archive for Uncategorized

HashCode, Locating characters and substrings in Strings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HashCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string string1 = "abcdefghijklmabcdefghijklm";
            char[] searchletters = { 'k', 'm' };

            Console.WriteLine(string1.GetHashCode());
            Console.WriteLine(searchletters.GetHashCode());

            Console.WriteLine(string1.LastIndexOf('a'));
            Console.WriteLine(string1.LastIndexOf('d', 18));
            Console.WriteLine(string1.IndexOf("hij"));
            Console.WriteLine(string1.IndexOfAny(searchletters));

        }
    }
}

Multithreading – 2 (Thread sleeps then wakes up)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Thread1
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread t = Thread.CurrentThread;
            t.Name = "Main tredi";

            Console.WriteLine(t.Name);
            Console.WriteLine(t.ThreadState);

            Thread.Sleep(5000);
            Console.WriteLine("Uyku bitti");
        }
    }
}

Multithreading-1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Thr
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread th = Thread.CurrentThread;
            th.Name = "Mainss";
            Console.WriteLine("This is {0}",th.Name);
            Console.WriteLine("This is {0}", th.ThreadState);
        }
    }
}

How to change default Visual Studio Warning Level?

http://mihai-nita.net/2010/05/10/changing-default-vs-warning-level/

In the link above , all the steps are explained carefully.

Tested it and it works.

 

 

File Open Modes – Reading and Writing Files

When you open a file, you must specify how it is to be opened. This means whether to create it from new, overwrite it and whether it’s text or binary, read or write and if you want to append to it. This is done using one or more file mode specifiers which are single letters “r”, “b”, “w”, “a” and + (in combination with the other letters). “r” – Opens the file for reading. This fails if the file does not exist or cannot be found. “w” – Opens the file as an empty file for writing. If the file exists, its contents are destroyed. “a” – Opens the file for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; this creates the file first if it doesn’t exist. Adding + to the file mode creates three new modes:

“r+” Opens the file for both reading and writing. (The file must exist.) “w+” Opens the file as an empty file for both reading and writing. If the file exists, its contents are destroyed. 
“a+” Opens the file for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist.

 

his table shows all of the combinations including both text and binary files. Generally you either read from or write to a text file, but not both at the same time.

With a binary file you can both read and write to the same file. The table below shows what you can do with each combination.

  • Mode Type of file Read Write Create Truncate
  • r text Read
  • rb+ binary Read
  • r+ text Read Write
  • r+b binary Read Write
  • rb+ binary Read Write
  • w text Write Create Truncate
  • wb binary Write Create Truncate
  • w+ text Read Write Create Truncate
  • w+b binary Read Write Create Truncate
  • wb+ binary Read Write Create Truncate
  • a text Write Create
  • ab binary Write Create
  • a+ text Read Write Create
  • a+b binary Write Create
  • ab+ binary Write Create

In my experience with files, unless you are just creating them (use “wb”) or reading them (use “rb” ) you can get away with using “w+b”. This lets you create a file from scratch.