How can I convert String to Int?

Try this: int x = Int32.Parse(TextBoxD1.Text); or better yet: int x = 0; Int32.TryParse(TextBoxD1.Text, out x); Also, since Int32.TryParse returns a bool you can use its return value to make decisions about the results of the parsing attempt: int x = 0; if (Int32.TryParse(TextBoxD1.Text, out x)) { // you know that the parsing attempt // … Read more

In C#, what is the difference between public, private, protected, and having no access modifier?

Access modifiers From docs.microsoft.com: public The type or member can be accessed by any other code in the same assembly or another assembly that references it. private The type or member can only be accessed by code in the same class or struct. protected The type or member can only be accessed by code in … Read more

Most Useful Attributes [closed]

[DebuggerDisplay] can be really helpful to quickly see customized output of a Type when you mouse over the instance of the Type during debugging. example: [DebuggerDisplay(“FirstName={FirstName}, LastName={LastName}”)] class Customer { public string FirstName; public string LastName; } This is how it should look in the debugger: Also, it is worth mentioning that [WebMethod] attribute with … Read more

How to delete all files and folders in a directory?

System.IO.DirectoryInfo di = new DirectoryInfo(“YourPath”); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { dir.Delete(true); } If your directory may have many files, EnumerateFiles() is more efficient than GetFiles(), because when you use EnumerateFiles() you can start enumerating it before the whole collection is returned, as opposed to GetFiles() where … Read more

LINQ Aggregate algorithm explained

The easiest-to-understand definition of Aggregate is that it performs an operation on each element of the list taking into account the operations that have gone before. That is to say it performs the action on the first and second element and carries the result forward. Then it operates on the previous result and the third … Read more

How to read embedded resource text file

You can use the Assembly.GetManifestResourceStream Method: Add the following usings using System.IO; using System.Reflection; Set property of relevant file: Parameter Build Action with value Embedded Resource Use the following code var assembly = Assembly.GetExecutingAssembly(); var resourceName = “MyCompany.MyProduct.MyFile.txt”; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)