Refernces: Int32.TryParse Method




Source


string test = "12345"

int result;

bool isParsed = Int32.TryParse(test, out result);


* 입력한 문자열값이 정상이면 isParsed = true, result는 변환된 int값이 입력됨.

* 입력한 문자열값이 비정상이면 isParsed = false, result는 0이 입력됨.


반응형


Sources 


List<T> listT = new List<T> { };


listT.Sort(delegate (T x, T y) {

    return x.ORDER.CompareTo(y.ORDER);

});



반응형

References


How can I sort generic list DESC and ASC?



Sources


1. Use Linq


var ascendingOrder = li.OrderBy(i => i);

var descendingOrder = li.OrderByDescending(i => i);



2. Not use Linq


li.Sort((a, b) => a.CompareTo(b)); // ascending sort

li.Sort((a, b) => -1* a.CompareTo(b)); // descending sort



3. Make to list.


li = li.OrderBy(i => i).ToList();

반응형


References


How to find the Mode in Array C#? 




Sources


int mode = x.GroupBy(v => v).OrderByDescending(g => g.Count()).First().Key;

반응형


References : Should I try to use the IE implementation of CSS Grid Layout?



.grid_container { 

    display: -ms-grid; -ms-grid-columns : 80% 20%; 

    display: grid; grid-template-columns: 80% 20%; 

    }


display에 grid대신 -ms-gird를 사용하고 grid-template-columns 대신 -ms-grid-columns를 사용한다.



또한 추가로 해당 그리드에 포함될 div에 col/row설정을 해준다.


.grid_item:nth-child(1) { -ms-grid-row:1; -ms-grid-column:1; }

.grid_item:nth-child(2) { -ms-grid-row:1; -ms-grid-column:2; }

.grid_item:nth-child(3) { -ms-grid-row:1; -ms-grid-column:3; }

.grid_item:nth-child(4) { -ms-grid-row:1; -ms-grid-column:4; }

.grid_item:nth-child(5) { -ms-grid-row:1; -ms-grid-column:5; }



자세한 내용은 참조 링크에 잘 나와있다.


반응형


References : runat=server 구문과 함께 form 태그 내부에 와야 합니다.



aspx의 CS파일 내부


public override void VerifyRenderingInServerForm(System.Web.UI.Control control)

{

     // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.

}


를 추가하자.



반응형

'Programming > C#' 카테고리의 다른 글

[C#-Linq] List<int>에서 최빈값(mode) 구하기  (0) 2018.09.20
[HTML] display:grtid; IE에서 사용하기  (0) 2018.07.24
[C#] JSON 문자열 만들기  (0) 2018.07.17
[LINQ] LINQ 중복 제거  (0) 2018.07.03
[WPF] Grid 칸 합치기  (0) 2018.06.12


참조 : How do I turn a C# object into a JSON string in .NET?



using System;

using System.Web.Script.Serialization;


public class MyDate

{

    public int year;

    public int month;

    public int day;

}


public class Lad

{

    public string firstName;

    public string lastName;

    public MyDate dateOfBirth;

}


class Program

{

    static void Main()

    {

        var obj = new Lad

        {

            firstName = "Markoff",

            lastName = "Chaney",

            dateOfBirth = new MyDate

            {

                year = 1901,

                month = 4,

                day = 30

            }

        };

        var json = new JavaScriptSerializer().Serialize(obj);

        Console.WriteLine(json);

    }

}


반응형


Reference 

[C#] linq를 사용하여 목록에서 중복 항목 제거

Converting from IEnumerable to List [duplicate]


IList<Something> variable = listVariable.GroupBy(x=>x.GROUP_BY_KEY).Select(grp => grp.First()).ToList();



* ToList()를 안하면 enumerable타입으로 반환됨.

반응형


1. Reference


https://stackoverflow.com/questions/23789647/merge-grid-columns



2. Source


일단 Grid의 칸을 합치는 방법은 없다.


단, 그리드 내의 컨텐츠를 그리드 여러 칸을 쓰도록 하는 방법을 통해 합쳐진 것처럼 보이게 한다.


<Grid>

    <Grid.RowDefinitions>

        <RowDefinition Height="*" />

        <RowDefinition Height="2*" />

        <RowDefinition Height="*" />

    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>

        <ColumnDefinition Width="*" />

        <ColumnDefinition Width="3*" />

    </Grid.ColumnDefinitions>

</Grid>

The 5 cells would be like:


Top-left: Grid.Column="0", Grid.Row="0"

Top-right: Grid.Column="1", Grid.Row="0"

Center: Grid.Column="0", Grid.Row="1", Grid.ColumnSpan="2"

Bottom-left: Grid.Column="0", Grid.Row="2"

Bottom-right: Grid.Column="1", Grid.Row="2"

반응형

'Programming > C#' 카테고리의 다른 글

[C#] JSON 문자열 만들기  (0) 2018.07.17
[LINQ] LINQ 중복 제거  (0) 2018.07.03
[WPF] 초기 화면 위치 설정  (0) 2018.06.08
[WPF] 아이콘 변경  (0) 2018.06.07
[WPF] 그리드 헤더 짤림 현상  (0) 2018.06.07

1. Reference


https://stackoverflow.com/questions/4019831/how-do-you-center-your-main-window-in-wpf

https://stackoverflow.com/questions/1545258/changing-the-start-up-location-of-a-wpf-window



2. SourceCode


A. Move to Center


private void CenterWindowOnScreen()

{

    double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;

    double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;

    double windowWidth = this.Width;

    double windowHeight = this.Height;

    this.Left = (screenWidth / 2) - (windowWidth / 2);

    this.Top = (screenHeight / 2) - (windowHeight / 2);

}


B. Set position


<Window x:Class="WpfApplication1.Window1" 

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

    Title="Window1" 

    Height="500" Width="500"

    WindowStartupLocation="Manual" 

    Left="0" Top="0">

</Window>

반응형

'Programming > C#' 카테고리의 다른 글

[LINQ] LINQ 중복 제거  (0) 2018.07.03
[WPF] Grid 칸 합치기  (0) 2018.06.12
[WPF] 아이콘 변경  (0) 2018.06.07
[WPF] 그리드 헤더 짤림 현상  (0) 2018.06.07
[C#] 문자열 검증. (null값, 공백확인)  (0) 2017.09.22

+ Recent posts