There is a bug or some called microsoft functionality in the microsoft flowlayout panel .I have used flowlayout panel in my current project in that panel i have add controls like : Checklistbox control,radiolistbox,regitry flags and many more they all had labels in their top with some fixed size but when i added in the panel then they all are docked in the panel (Top) property but size of the labels was remain same.then i come to know it's a bug then i used panel instead of flowlayout panel.
Algorithms in C# (Anagram Method)
Input :-
1:- cba
2:- dsef
3:- sandy
Output :-
1:- abc
2:- defs
3:- adnsy
This is called alphabetized sorting using Anagram method.
To Use Anagram Method :-
Dictionary : 4556 ms
If we use generic list in dictionary then it will take longer time to compute
Dictionary : 5647 ms
Namespace :-
using System;
using System.Collections.Generic;
using System.IO;
Public class Anagrams
{
public static void Main()
{
Read and sort dictionary
var data = ReadText();
Read in user input and show anagrams
string lineToRead;
while ((lineToRead = Console.ReadLine()) != null)
{
ShowOutput(data, lineToRead);
}
}
Public Dictionary ReadText()
{
var data = new Dictionary();
Read each line
using (StreamReader readWholeText = new StreamReader("Some File .Text"))
{
string line;
while ((line = readWholeText.ReadLine()) != null)
{
Alphabetize the line for the key,Then add to the string
string alphabetize = Alphabetize(line);
string tempString = string.Empty;
if (data.TryGetValue(alphabetize, out tempString))
{
data[alphabetize] = tempString + "," + line;
}
else
{
data.Add(alphabetize, line);
}
}
}
return data;
}
Convert the text and sort it according to alphabet.
Public string Alphabetize(string text)
{
// Convert to char array, then sort and return
char[] arrayOfLine = text.ToCharArray();
Array.Sort(arrayOfLine);
return new string(arrayOfLine);
}
This method will show the output.
Public void ShowOutput(Dictionary objDictionary, string temp)
{
// Write value for alphabetized word
string tempText;
if (objDictionary.TryGetValue(Alphabetize(temp), out tempText))
{
Console.WriteLine(tempText);
}
else
{
Console.WriteLine("-");
}
}
}
1:- cba
2:- dsef
3:- sandy
Output :-
1:- abc
2:- defs
3:- adnsy
This is called alphabetized sorting using Anagram method.
To Use Anagram Method :-
Dictionary
If we use generic list in dictionary then it will take longer time to compute
Dictionary
Namespace :-
using System;
using System.Collections.Generic;
using System.IO;
Public class Anagrams
{
public static void Main()
{
Read and sort dictionary
var data = ReadText();
Read in user input and show anagrams
string lineToRead;
while ((lineToRead = Console.ReadLine()) != null)
{
ShowOutput(data, lineToRead);
}
}
Public Dictionary
{
var data = new Dictionary
Read each line
using (StreamReader readWholeText = new StreamReader("Some File .Text"))
{
string line;
while ((line = readWholeText.ReadLine()) != null)
{
Alphabetize the line for the key,Then add to the string
string alphabetize = Alphabetize(line);
string tempString = string.Empty;
if (data.TryGetValue(alphabetize, out tempString))
{
data[alphabetize] = tempString + "," + line;
}
else
{
data.Add(alphabetize, line);
}
}
}
return data;
}
Convert the text and sort it according to alphabet.
Public string Alphabetize(string text)
{
// Convert to char array, then sort and return
char[] arrayOfLine = text.ToCharArray();
Array.Sort(arrayOfLine);
return new string(arrayOfLine);
}
This method will show the output.
Public void ShowOutput(Dictionary
{
// Write value for alphabetized word
string tempText;
if (objDictionary.TryGetValue(Alphabetize(temp), out tempText))
{
Console.WriteLine(tempText);
}
else
{
Console.WriteLine("-");
}
}
}
MSIL code for Singleton and Static class
MSIL code for singleton
L_0000: ldsfld class Perls.Metadata Perls.Metadata::Instance
L_0005: ldarg.0
L_0006: ldloca.s data
L_0008: callvirt instance bool Perls.Metadata::TryGetFile(string, class Perls.FileData&)
MSIL code for static class
L_0000: ldarg.0
L_0001: ldloca.s data
L_0003: call bool Perls.Metadata::TryGetFile(string, class Perls.FileData&)
L_0000: ldsfld class Perls.Metadata Perls.Metadata::Instance
L_0005: ldarg.0
L_0006: ldloca.s data
L_0008: callvirt instance bool Perls.Metadata::TryGetFile(string, class Perls.FileData&)
MSIL code for static class
L_0000: ldarg.0
L_0001: ldloca.s data
L_0003: call bool Perls.Metadata::TryGetFile(string, class Perls.FileData&)
Comparison between NullCheckSingleton and OptimizedSingleton in C#
NullCheckSingleton
public sealed class SampleProgram
{
static readonly SampleProgram _instance;
public static readonly SampleProgram Instance
{
if (_instance == null)
{
_instance = new SampleProgram();
}
return _instance;
}
SampleProgram()
{
}
}
Optimized singleton
public sealed class SampleProgram
{
static readonly SampleProgram _instance = new SampleProgram();
public static readonly SampleProgram Instance
{
get
{
return _instance;
}
}
SampleProgram()
{
}
}
Optimized singleton is much faster than NullcheckSingleton Have a look on the above example and as i am discussed in my previous thread about the time comparison in both singleton pattern.
[Reference Jon Skeet's thorough singleton page.]
public sealed class SampleProgram
{
static readonly SampleProgram _instance;
public static readonly SampleProgram Instance
{
if (_instance == null)
{
_instance = new SampleProgram();
}
return _instance;
}
SampleProgram()
{
}
}
Optimized singleton
public sealed class SampleProgram
{
static readonly SampleProgram _instance = new SampleProgram();
public static readonly SampleProgram Instance
{
get
{
return _instance;
}
}
SampleProgram()
{
}
}
Optimized singleton is much faster than NullcheckSingleton Have a look on the above example and as i am discussed in my previous thread about the time comparison in both singleton pattern.
[Reference Jon Skeet's thorough singleton page.]