Let’s say you have a class like that: public class Student { public string Name { get; set; } public string Surname { get; set; } public DateTime DateCreated { get; set; } … } If you want to join the name values of that class then you can use the code below: using System.Linq […]
Tag: class
How to add some content to the right side of CardHeader on Bootstrap
<div class=”card-header container-fluid”> <div class=”col-md-10″><h3>Your Header Title</h3></div> <div class=”col-md-2 float-right”>The content you want to add to the right side.</div> </div>
How to align inconsistently sized logos with CSS
These 3 lines will save you (fit, line up, remove background): aspect-ratio: 3/2; object-fit: contain; mix-blend-mode:color-burn; Let’s see how you can use that: In the body section, we have a div with the “photoDiv” class. <div class=”photoDiv”> <img src=”1.png”> <img src=”2.png”> <img src=”3.png”> <img src=”4.png”> <img src=”5.png”> </div> And here is the magical CSS: <style> […]
Constructor for a static class in C#
C# has a static constructor for this purpose. static class YourClass { static YourClass() { // perform initialization here } } A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or […]
How to apply two classes to a single element in CSS
Let’s say you want to use 2 or more classes for a div. Then you should use these classes inside the class attribute, separated by whitespace: <div class=”myFirstClass mySecondClass”></div> To target elements that contain all of the specified classes, use this CSS selector (no space) in your CSS file: .myFirstClass.mySecondClass {}
How to make the default class type ‘public’ instead of ‘internal’ in Visual Studio
VS2012: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class VS2015: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class VS2017(RC): C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class VS2017(Professional): C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class VS2019 (Enterprise): C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs VS2019 (Professional): C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs Starting with Visual Studio 2022 VS is a 64 bit application, meaning the item templates are in C:\Program Files\… instead of C:\Program Files […]
Add and Remove classes from element in Javascript
classList is pretty smart and the most modern system of manipulating CSS class names in elements via JavaScript. Adding class name: const element = document.getElementById(‘txtMyText’); element.classList.add(‘myClass’); Removing class name: const element = document.getElementById(‘txtMyText’); element.classList.remove(‘myClass’); Removing multiple class names: const element = document.getElementById(‘txtMyText’); element.classList.remove(‘myClass1’, ‘myClass2’) Thanks to clubmate.fi
How to apply a custom CSS class to Devexpress components
For all the Devex Components, you can use ControlStyle > CssClass property to apply your custom CSS class (Example 1 and 2) or you can do it with parameter (if it is allowed – as in Example 3). Here is 3 examples for MVC: @Html.DevExpress().SpinEditFor(m => m.Books.Rating, settings => { settings.Properties.SpinButtons.ShowIncrementButtons = true; settings.Properties.Increment = […]
Constructors and Its Types in C#
Constructor is a special method of the class that is automatically invoked when an instance of the class is created is called a constructor. The main use of constructors is to initialize the private fields of the class while creating an instance for the class. When you have not created a constructor in the class, the compiler […]
What does the word ‘new’ mean exactly in C#?
In C# (and many other languages) you will find that you use new often as it is fundamental to using types and classes. The new keyword does pretty much what it says: it will create a new instance of a class or type, assigning it a location in memory. Let me try and illustrate this. Company company; Here […]
How to access session variable in App_Code class file?
string MySessionValue = System.Web.HttpContext.Current.Session[“YourSessionVariable”].ToString();
Using View Model to pass Multiple Models in Single View in MVC
In MVC we cannot pass multiple models from a controller to the single view. There are a few solution for that problem. But in this article we will use View Model. Here is the solution: