Skip to content

Category: C#

C# The reason why be shown same perfomance of List VS Array

The List class contains an internal array and exposes methods and properties that, among other things, allow read and write access to the elements of the internal array. The List: a Homogeneous, Self-Redimensioning Array Conclusion… The List class has same performance of array. but needs multiple memories.

C# console log

System.Diagnostics.Debug.WriteLine(“MESSAGE”);

C# get app settings

ConfigurationManager.AppSettings[someKey] -> return someValue <configuration>   <appSettings>    <add key=”someKey” value=”someValue”/>  </appSettings> </configuration>

C# get url parameter

HttpContext.Current.Request.UrlReferrer.Query.Substring(1);ex)http://000.000.000.000:0000/index.html?A=B&C=D-> A=B&C=D

C# TransactionScope timeout

new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes([minutes]));

Excel get column index from column name

colIndexToAlpha(27) -> return AA alphaToColIndex(AA) -> return 27 // get cellReference’s column from column indexpublic string colIndexToAlpha(int colIndex) {  List<string> colNameList = new List<string>();  int num1 = Convert.ToInt32(colIndex) – 1;  int num2 = 0;  int num3 = 0;  while (true) {    num2 = num1 / 26;    num3 = num1 – 26 * num2;    […]

Excel get row index and column name from cell referance

private Regex regexRow = new Regex(@”d+”); public int getRowIndex(string cellReferance) {  return int.Parse(regexRow.Match(cellName).Value);} private Regex regexCol = new Regex(“[A-Za-z]+”); private string getColumnName(string cellReferance) {  return regexCol.Match(cellName).Value;}

C# -> JS all files and directories

get all files and directories in C# and set all files and directories in JS C#GetFilesAndDirectories(@”C:”, true); private List<object> GetFilesAndDirectories(string path, bool isRoot = false) {  List<object> fileList = new List<object>();  Dictionary<string, object> fileItem = new Dictionary<string, object>();  if (isRoot) {    fileItem = new Dictionary<string, object>();    fileItem[“type”] = “dir”;    fileItem[“value”] = path.Substring(path.LastIndexOf(Path.DirectorySeparatorChar) […]

C# File download 日本語ファイル名 in IE

 string filename = “test.xls”; string filePath = “c:\text.xls”;  FileStream sourceFile = new FileStream(filePath, FileMode.Open); float FileSize; FileSize = sourceFile.Length; byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)sourceFile.Length); sourceFile.Close();  HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent();// 日本語ファイル名対応(japanese filename support) HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding(“shift_jis”); HttpContext.Current.Response.AddHeader(“Content-Disposition”, “attachment; filename=” + filename); HttpContext.Current.Response.ContentType = “application/octet-stream”; HttpContext.Current.Response.BinaryWrite(getContent); HttpContext.Current.Response.End(); // IEでは.NET利用し、システム(OS)言語によりエンコードを勝手に判断するらしい。