When should you use var keyword in C#?
Check out Eric Lippert’s blog article http://blogs.msdn.com/b/ericlippert/archive/2011/04/20/uses-and-misuses-of-implicit-typing.aspx
See also http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c
When should you use var keyword in C#?
Check out Eric Lippert’s blog article http://blogs.msdn.com/b/ericlippert/archive/2011/04/20/uses-and-misuses-of-implicit-typing.aspx
See also http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c
If you want to know the version of currently executing managed assembly, you can use Reflection.Assembly.
Here is code snippet which can be used to do get managed assembly version.
private string GetVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
I searched google for how to valicate URL in C# and most results say using a regular expression. Eventually I found Uri.TryCreate which is a built in method in C# to check if a string is a valid URL
Uri uri = null;
if (!Uri.TryCreate(url, UriKind.Absolute, out uri) || null == uri)
{
//Invalid URL
return false;
}
Reference:
http://msdn.microsoft.com/en-us/library/ms131572(v=VS.90).aspx
Tired of code like this?
public string Foo
{
get { return foo; }
set
{
if (value == null)
value = String.Empty;
foo = value;
}
}
public string Bar
{
get { return bar; }
set
{
if (value == null)
value = String.Empty;
bar = value;
}
}
Use coalescing operator to make your code a bit more readable.
CSharp sample for reading from a text file and writing to a text file.
//Reading from a text file
System.IO.StreamReader srFile = new System.IO.StreamReader(@"c:\foo.txt");
string str = srFile.ReadToEnd();
srFile.Close();
//Writing to a text file
string lines = "foobar";
System.IO.StreamWriter swFile = new System.IO.StreamWriter(@"c:\bar.txt");
swFile.WriteLine(lines);
swFile.Close();