How do I call a getter or setter in C#

localMyClass.myVal = 42; Getters and setters let you treat the values like public properties. The difference is, you can do whatever you want inside the functions that do the getting and setting. Examples: store other variables private int _myVal, myOtherVal; public int MyVal { get; set { _myVal = value; myOtherVal++; } } make numbers … Read more

C# Unicode string output

First, change the output encoding to UTF8: Console.OutputEncoding = Encoding.UTF8; Console.WriteLine(“добры дзень”); Now you’ll still see question marks. The reason is that the default console’s font doesn’t support Cyrillic letters. Change the font of the console: If you’re lucky, you should find a different font with Unicode support: Change the font, and you should be … Read more

C# Casting with objects to Enums

Something like this probably will help you: public T dosomething<T>(object o) { T enumVal= (T)Enum.Parse(typeof(T), o.ToString()); return enumVal; } But this will work only with enums, for clear reason of using Enum.Parse(..) And use this like, for example: object o = 4; dosomething<Crustaceans>(o); That will return Toad in your case.

Simple Examples of joining 2 and 3 table using lambda expression

Code for joining 3 tables is: var list = dc.Orders. Join(dc.Order_Details, o => o.OrderID, od => od.OrderID, (o, od) => new { OrderID = o.OrderID, OrderDate = o.OrderDate, ShipName = o.ShipName, Quantity = od.Quantity, UnitPrice = od.UnitPrice, ProductID = od.ProductID }).Join(dc.Products, a => a.ProductID, p => p.ProductID, (a, p) => new { OrderID = a.OrderID, … Read more

Lazy initialization in .NET 4

The purpose of the Lazy feature in .NET 4.0 is to replace a pattern many developers used previously with properties. The “old” way would be something like private MyClass _myProperty; public MyClass MyProperty { get { if (_myProperty == null) { _myProperty = new MyClass(); } return _myProperty; } } This way, _myProperty only gets … Read more

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