using

how to convert text readed from barcode to arabic text

孤街浪徒 提交于 2019-12-24 00:56:34
问题 I have barcode image with type "pdf417",it content a arabic text , When read it using barcode it through a text like this "ÃÍãÏ#" how can I convert this text to its original text (arabic) 回答1: If your method gives you a byte[] use: var str = Encoding.UTF8.GetString(yourBytes); or, perhaps var str = Encoding.GetEncoding(1256) // 1256 is the Windows Arabic codepage .GetString(yourBytes); If your method gives you a string do this: // iso-8859-1 is a codepage that can be used to convert back some

streamwriter declared static vs with an using statement

穿精又带淫゛_ 提交于 2019-12-24 00:26:46
问题 I'm VERY new to C# so please allow me some ignorance :) (I've tried searching around to understand the reason for the difference in performance I'm seeing but as of yet don't have a definitive answer so I thought I'd ask the knowledgable audience on here...) Basically... if I use streamwriter something like: public static class Logging { readonly static object DebugWriter = new object(); public static void Log(string msg) { lock (DebugWriter) { using (StreamWriter writer = new StreamWriter(

SQLConnection with the Using statement, calling SQLDataReader from inside it?

老子叫甜甜 提交于 2019-12-23 20:14:22
问题 Just want to make sure this is the best way to call a connection, and grabbing data from a database, or should I some how call the datareader outside of the using statement? (in order to have the connection close quicker?) or is there anything you would personal change to this? using (SqlConnection cn = new SqlConnection(connStr)) { using (SqlCommand cm = new SqlCommand(connStr, cn)) { cm.CommandType = CommandType.StoredProcedure; cm.CommandText = "GetExchRatesByDate"; cm.Parameters.Add("

How to use object initializers with using statements?

本小妞迷上赌 提交于 2019-12-23 17:46:00
问题 Is there any way to refactor this code to not have to use a temporary variable and still use the syntactic sugar associated with object initializers? FrmSomeForm someTempForm = new FrmSomeForm() { SomePropA = "A", SomePropB = "B", SomePropC = "C" }; using (FrmSomeForm someForm = someTempForm) { someForm.ShowDialog(); } 回答1: using (FrmSomeForm someForm = new FrmSomeForm(){ SomePropA = "A", SomePropB = "B", SomePropC = "C" }) { someForm.ShowDialog(); } doesn't this work? oO 回答2: using

SQL Server equivalent of MySQL's USING

被刻印的时光 ゝ 提交于 2019-12-23 10:09:11
问题 In MySQL, you can use the keyword USING in a join when you join on columns from different tables with the same name. For example, these queries yield the same result: SELECT * FROM user INNER JOIN perm USING (uid) SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid Is there an equivalent shortcut in SQL Server? 回答1: nope, have to use: SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid 回答2: No, SQL Server does not support this kind of shortcut. I would like to point out that even

Will a IDisposable be disposed if the using block returns?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:27:01
问题 For example using(var something = GetSomething()) { something.DoSomething(); if(something.IsX()) return true; } return false; 回答1: Yes, absolutely. The Dispose method is called however the using statement is executed, unless it was an abrupt whole-process termination. The most common cases are: A return within the block An exception being thrown (and not caught) within the block Reaching the end of the block naturally Basically a using statement is mostly syntactic sugar for a try / finally

Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution

被刻印的时光 ゝ 提交于 2019-12-23 08:47:17
问题 I have a C# console application with three assemblies: Main , Common and Utilities . In a file in the Main assembly, Main.cs , I have the line: using Utilities; In a directory within the Common assembly, I have the DLL IBM.Data.DB2.dll . In the Utilities assembly, I have a source module which accesses said dll . Utilities have a Reference to IBM.Data.DB2 . In a source file within this assembly, Util.cs , I have the line: using IBM.Data.DB2; If, within a method in this file, I make any

Do we need to close a C# BinaryWriter or BinaryReader in a using block?

社会主义新天地 提交于 2019-12-23 07:38:59
问题 Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here } Do we need to close the BinaryWriter? If not, why? 回答1: So long as it's all wrapped up in a using block then you don't need to explicitly call Close . The using block will ensure that the object is disposed, and the Close and Dispose methods are interchangeable on BinaryWriter . (The Close method just calls Dispose behind the scenes.) 回答2: Putting it in a using

In C# are the `using` directives of the base class inherited by the child class?

痞子三分冷 提交于 2019-12-23 07:29:07
问题 Let's say we have a base class Rectangle and a derived class Square : namespace Shapes { using System.Foo; public class Rectangle { public Rectangle(int l, int w){} } } namespace Shapes { public class Square : Rectangle public Square(int l, int w){} } Does the Square class have to explicitly say that it is using System.Foo ? I'm getting erratic results. In one project the using directives seem to be inherited and in a web application they aren't. 回答1: using statements, in this context, don't

Curious C# using statement expansion

笑着哭i 提交于 2019-12-23 06:47:13
问题 I've run ildasm to find that this: using(Simple simp = new Simple()) { Console.WriteLine("here"); } generates IL code that is equivalent to this: Simple simp = new Simple(); try { Console.WriteLine("here"); } finally { if(simp != null) { simp.Dispose(); } } and the question is why the hell does it check null in the finally? The finally block will only be executed if the try block is executed, and the try block will only be executed if the Simple constructor succeeds (I.e. does not throw an