how to set the get and the set of a var c# code example

Example 1: set in javascript

let mySet = new Set()

mySet.add(1)           // Set [ 1 ]
mySet.add(5)           // Set [ 1, 5 ]
mySet.add(5)           // Set [ 1, 5 ]
mySet.add('some text') // Set [ 1, 5, 'some text' ]
let o = {a: 1, b: 2}
mySet.add(o)

mySet.add({a: 1, b: 2})   // o is referencing a different object, so this is okay

mySet.has(1)              // true
mySet.has(3)              // false, since 3 has not been added to the set
mySet.has(5)              // true
mySet.has(Math.sqrt(25))  // true
mySet.has('Some Text'.toLowerCase()) // true
mySet.has(o)       // true

mySet.size         // 5

mySet.delete(5)    // removes 5 from the set
mySet.has(5)       // false, 5 has been removed

mySet.size         // 4, since we just removed one value

console.log(mySet)
// logs Set(4) [ 1, "some text", {…}, {…} ] in Firefox
// logs Set(4) { 1, "some text", {…}, {…} } in Chrome

Example 2: How to set the value to be selected in the dropdownlist in mvc

Here , Model is a dynamic object and from that modal we are 
	fetching States property which is of list type.
	Here , employee is an employee object and from that object
	we are fetching state property which is of string type.
@foreach (var S in Model.States)
            {
                if (S.StateName == employee.State)
                {
                    <option value="@S.StateName" selected="selected">@S.StateName</option>                             
                }
                else
                {
                    <option value="@S.StateName">@S.StateName</option>                             
                }
            }