|
|
C++, pasted just now:
|
ImageView.java
|
'Android' 카테고리의 다른 글
[AlertDialog] (0) | 2010.08.18 |
---|---|
[MenuTest] (0) | 2010.08.18 |
[LifeCycle] (0) | 2010.08.17 |
[ShapeEx] (0) | 2010.08.16 |
[.java로 View Control] (0) | 2010.08.16 |
LifeCycleTest.java
|
'Android' 카테고리의 다른 글
[MenuTest] (0) | 2010.08.18 |
---|---|
[ImageView] (0) | 2010.08.17 |
[ShapeEx] (0) | 2010.08.16 |
[.java로 View Control] (0) | 2010.08.16 |
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
by Parsing
|
by Regular Expression
C++, pasted just now:
|
1. drawText() 이용
2. moveTo(), lineTo() 이용
|
|
'Android' 카테고리의 다른 글
[ImageView] (0) | 2010.08.17 |
---|---|
[LifeCycle] (0) | 2010.08.17 |
[.java로 View Control] (0) | 2010.08.16 |
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
XML 문법 (0) | 2010.08.13 |
|
|
'Android' 카테고리의 다른 글
[LifeCycle] (0) | 2010.08.17 |
---|---|
[ShapeEx] (0) | 2010.08.16 |
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
XML 문법 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
'VIM 강좌' 카테고리의 다른 글
용어 tabstop shiftwidth (0) | 2010.08.23 |
---|---|
ctags & cscope (0) | 2010.08.15 |
vim 사용법 (0) | 2010.06.12 |
:ta [name] :: name과 일치하는 태그 위치로 이동
ctrl + ] :: 커서가 위치하고 있는 함수나 구조체의 정의로 이동
ctrl + t :: 이전 위치로 돌아오기
:ts [name] :: name과 일치하는 태그 목록 출력
:ta /[name]:: name과 일치하는 태그 목록 출력
:tj [name] :: 목록이 한개인 경우 이동, 여러개인 경우 목록 출력
:tn :: 다음 태그로 이동 (tag next)
:tp :: 이전 태그로 이동 (tag previous)
:tags :: 이동한 태그 히스토리 목록 출력
==============================
'VIM 강좌' 카테고리의 다른 글
용어 tabstop shiftwidth (0) | 2010.08.23 |
---|---|
folding (0) | 2010.08.15 |
vim 사용법 (0) | 2010.06.12 |
C++, pasted 1 second ago:
|
'C++' 카테고리의 다른 글
다중 상속의 문제점 (0) | 2010.08.16 |
---|---|
생성자와 소멸자 (0) | 2010.08.13 |
c++ 오버라이딩 (0) | 2010.07.03 |
동적 할당 0614 (0) | 2010.06.14 |
c++ 0610 (0) | 2010.06.10 |
RelativeLayoutTest.java 1. findViewById()로 버튼 객체 선택. final로 선언되어 있어야 함. 2. 버튼에 이벤트 리스너 설정.
|
main.xml
|
'Android' 카테고리의 다른 글
[ShapeEx] (0) | 2010.08.16 |
---|---|
[.java로 View Control] (0) | 2010.08.16 |
XML 문법 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
[CustomView] 3. RobotView 그림 위치 지정 - 성공 (0) | 2010.08.12 |
arr = new int [arraySize];
'C++' 카테고리의 다른 글
다중 상속의 문제점 (0) | 2010.08.16 |
---|---|
C++ 생성자 (0) | 2010.08.13 |
c++ 오버라이딩 (0) | 2010.07.03 |
동적 할당 0614 (0) | 2010.06.14 |
c++ 0610 (0) | 2010.06.10 |
'Android' 카테고리의 다른 글
[.java로 View Control] (0) | 2010.08.16 |
---|---|
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
[CustomView] 3. RobotView 그림 위치 지정 - 성공 (0) | 2010.08.12 |
[CustomView] 1. 그림 정가운데 출력 (0) | 2010.08.12 |
package net.itisn.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; public class RobotView extends View implements Runnable { private final static int STEP = 10; private Drawable image; private int viewWidth, viewHeight; private int imageWidth, imageHeight; private int x, y; public RobotView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub image = this.getResources().getDrawable(R.drawable.su); Thread thread = new Thread(this); thread.start(); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub image.setBounds(x, y, x + imageWidth, y + imageHeight); image.draw(canvas); super.onDraw(canvas); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { // TODO Auto-generated method stub viewWidth = this.getWidth(); viewHeight = this.getHeight(); imageWidth = image.getIntrinsicWidth(); imageHeight = image.getIntrinsicHeight(); x = viewWidth / 2 - imageWidth / 2; y = viewHeight / 2 - imageHeight / 2; super.onSizeChanged(w, h, oldw, oldh); } @Override public void run() { // TODO Auto-generated method stub for (; ;) { try { Thread.sleep(500); y = Math.min(viewHeight - imageHeight, y + STEP); this.postInvalidate(); } catch(InterruptedException e) { e.printStackTrace(); } } } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub x = (int)event.getX(); y = (int)event.getY(); this.invalidate(); return super.onTouchEvent(event); } } |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <net.itisn.test.RobotView android:id="@+id/su" android:layout_height="wrap_content" android:layout_width="wrap_content" /> </LinearLayout> |
'Android' 카테고리의 다른 글
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
---|---|
XML 문법 (0) | 2010.08.13 |
[CustomView] 3. RobotView 그림 위치 지정 - 성공 (0) | 2010.08.12 |
[CustomView] 1. 그림 정가운데 출력 (0) | 2010.08.12 |
[CustomView] 0. RobotView 생성 (0) | 2010.08.11 |
onSizeChanged()를 오버라이드하여 그 안에 작성한다.
package net.itisn.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; public class RobotView extends View { private Drawable image; private int viewWidth, viewHeight; private int imageWidth, imageHeight; private int x, y; public RobotView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub image = this.getResources().getDrawable(R.drawable.su); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub image.draw(canvas); super.onDraw(canvas); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { // TODO Auto-generated method stub viewWidth = this.getWidth(); viewHeight = this.getHeight(); imageWidth = image.getIntrinsicWidth(); imageHeight = image.getIntrinsicHeight(); x = viewWidth / 2 - imageWidth / 2; y = viewHeight / 2 - imageHeight / 2; image.setBounds(x, y, x + imageWidth, y + imageHeight); super.onSizeChanged(w, h, oldw, oldh); } } |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <net.itisn.test.RobotView android:id="@+id/su" android:layout_height="wrap_content" android:layout_width="fill_parent" /> </LinearLayout> |
'Android' 카테고리의 다른 글
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
---|---|
XML 문법 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
[CustomView] 1. 그림 정가운데 출력 (0) | 2010.08.12 |
[CustomView] 0. RobotView 생성 (0) | 2010.08.11 |
package net.itisn.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; public class RobotView extends View { private Drawable image; public RobotView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub image = this.getResources().getDrawable(R.drawable.su); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub int viewWidth = this.getWidth(); int viewHeight = this.getHeight(); int imageWidth = image.getIntrinsicWidth(); int imageHeight = image.getIntrinsicHeight(); int x = viewWidth / 2 - imageWidth / 2; int y = viewHeight / 2 - imageHeight / 2; image.setBounds(x, y, x + imageWidth, y + imageHeight); image.draw(canvas); super.onDraw(canvas); } } |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <net.itisn.test.RobotView android:id="@+id/su" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> |
'Android' 카테고리의 다른 글
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
---|---|
XML 문법 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
[CustomView] 3. RobotView 그림 위치 지정 - 성공 (0) | 2010.08.12 |
[CustomView] 0. RobotView 생성 (0) | 2010.08.11 |
|
DB 0xeb, 0x4e, 0x90, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x02, 0xe0, 0x00, 0x40, 0x0b, 0xf0, 0x09, 0x00
DB 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x29, 0xff
DB 0xff, 0xff, 0xff, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x2d, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x46, 0x4c
DB 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c
DB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a
DB 0x04, 0x8., 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09
DB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb
DB 0xee, 0xf4, 0xeb, 0xfd, 0x0a, 0x0a, 0x68, 0x65
DB 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x88, 0x6f, 0x72
DB 0x6c, 0x64, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
~ (약 18만 행)
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
|
;hello-os
;이하는 표준적인 FAT12 포맷 플로피디스크를 위한 서술
DB 0xeb, 0x4e, 0x90
DB "HELLOIPL" ;부트섹터의 이름을 자유롭게 써도 좋음
DW 512 ;1섹터의 크기
DB 1 ;클러스터의 크기 (1섹터로 해야 함)
DW 1 ;예약된 섹터의 수
DB 2 ;디스크의 FAT 테이블의 수
DW 224 ;루트 디렉토리 엔트리의 수 (보통은 224엔트리)
DW 2880 ;디스크의 총 섹터 수 (2880섹터로 해야 함)
DB 0xf0 ;미디어 타입 (0xf0으로 해야 함)
DW 9 ;하나의 FAT 테이블의 섹터 수 (9섹터로 해야 함)
DW 18 ;1트랙의 섹터 수 (18로 해야 함)
DW 2 ;헤드의 수 (2로 해야 함)
DD 0 ;파티션을 사용하지 않으므로 이곳은 반드시 0
DB 0, 0, 0x29 ;잘 모르겠지만 이 값을 넣어 두면 좋다고 함
DD 0xffffffff ;아마 볼륨의 시리얼 번호
DB "HELLO-OS" ;디스크의 이름
DB "FAT12 " ;포맷의 이름 (8바이트)
RESB 18 ;어쨋든 18바이트 남겨둠
;프로그램 본체
DB 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c
DB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a
DB 0x04, 0x83, 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09
DB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb
DB 0xee, 0xf4, 0xeb, 0xfd
;메시지 부분
DB 0x0a, 0x0a ;줄바꿈 2개
DB "hello, world"
DB 0x0a ;줄바꿈
DB 0
RESB 0x1fe-$ ;0x001fe(510바이트, 0x001fe 앞)까지 0x00으로 채움
DB 0x55, 0xaa
;이하는 부트섹터 이외의 부분에 기술
DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB 4600
DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB 1469432 |
Class를 생성할 때 또는 정보를 얻고자 할때 context가 parameter로 많이 사용이 되는데
이는 Class memory를 할당하거나 정보를 얻고자 하는 memory block 정보를 검색하기 위해서
어떠한 application에서 요청했는지가 필요하기 때문입니다.
예를들어서 TextView를 생성하는 경우 내부적으로는 heap memory를 할당하고
해당 memory pointer를 Application context 정보를 기반으로 관리하는 것이고
Application이 종료하게 되면 해당 application이 사용하는 heap memory를 free하는데 사용합니다.
AttributeSet은 일반적으로 layout xml에서 android:text="@string/hello"와 같이 설정을 하는데
LayoutInflater class를 사용해서 TextView를 실시간으로 생성하게 되는 경우
TextView의 속성을 지정할 때 사용하는 class입니다.
AttributeSet은 SDK를 보시면 아시겠지만 XML에 기반한 class입니다.
package net.itisn.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; public class RobotView extends View { private Drawable image; public RobotView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub image = this.getResources().getDrawable(R.drawable.su); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub image.setBounds(0, 0, 128, 128); image.draw(canvas); //layout(0, 0, 128, 128); super.onDraw(canvas); } } |
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<net.itisn.test.MyView android:id="@+id/su"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/> <net.itisn.test.SunView android:id="@+id/icon" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> |
'Android' 카테고리의 다른 글
[RelativeLayout] 0. 레이아웃 만들기 (0) | 2010.08.13 |
---|---|
XML 문법 (0) | 2010.08.13 |
[CustomView] 4. Thread 이용하여 그림 움직이기 (0) | 2010.08.12 |
[CustomView] 3. RobotView 그림 위치 지정 - 성공 (0) | 2010.08.12 |
[CustomView] 1. 그림 정가운데 출력 (0) | 2010.08.12 |
using System; class MainClass { public static void Main() { Console.WriteLine("A simple C# program."); } } |
using System; class MainClass { public static void Main(string[] args) { foreach (string arg in args) Console.WriteLine("Arg: {0}", arg); } } |
using System; class MainClass { public static int Main() { Console.WriteLine("Hello, Universe!"); return (0); } } |
using System; class MainClass { static void Main() { } static int Main() { } static void Main(string[] args) { } static int Main(string[] args) { } } |
class MainClass { static void Main(string[] args) { if (args[0][0] == '-') { System.Console.WriteLine("-"); } } } |
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { Console.WriteLine("{0} command line arguments were specified:", args.Length); foreach (string arg in args) Console.WriteLine(arg); } } |
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { Console.WriteLine("A simple C# program."); System.Console.WriteLine("A simple C# program."); } } |
이 어트리뷰트는 해당 응용 프로그램이 COM형식을 이용하는 경우에 (단지 이 경우에만 해당하는 것인데) 해당 응용 프로그램이
단일 스레드 아파트(single threaded apartment, STA) 모델로 설정되어야 한다는 것을 런타임에게 알려주는 역할을 한다.
해당 응용 프로그램에서 COM 형식을 이용하지 않는다면, [STAThread] 어트리뷰트는 무시되기 때문에 삭제해도 무방하다.
using System; namespace HelloWorld { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { System.Console.WriteLine("Hello world from C#"); } } } |
using System; namespace Counter { class MyClass { } } class MainClass { public static void Main() { Counter.MyClass my = new Counter.MyClass(); } } |
using ThatConsoleClass = System.Console; class MainClass { public static void Main() { ThatConsoleClass.WriteLine("Hello"); } } |
using System; namespace Counter { class MyClass { public MyClass() { Console.WriteLine("Counter1 namespace."); } } } namespace Counter2 { class MyClass { public MyClass() { Console.WriteLine("Counter2 namespace."); } } } class MainClass { public static void Main() { Counter.MyClass m1 = new Counter.MyClass(); Counter2.MyClass m2 = new Counter2.MyClass(); } } |
using System; using Counter; namespace Counter { class MyClass { } } namespace Counter { class MySecondClass { } } class MainClass { public static void Main() { MyClass m = new MyClass(); MySecondClass cu = new MySecondClass(); } } |
using System; namespace NS1 { class ClassA { public ClassA() { Console.WriteLine("constructing ClassA"); } } namespace NS2 { class ClassB { public ClassB() { Console.WriteLine("constructing ClassB"); } } } } class MainClass { public static void Main() { NS1.ClassA a = new NS1.ClassA(); NS1.NS2.ClassB b = new NS1.NS2.ClassB(); } } |
using System; using Counter; using AnotherCounter; using Ctr = Counter; namespace Counter { class MyClass { } } namespace AnotherCounter { class MyClass { } } class MainClass { public static void Main() { Ctr::MyClass m = new Ctr::MyClass(); } } |
namespace CompanyName { public class Car { public string make; } } namespace DifferentCompany { public class Car { public string make; } } class MainClass { public static void Main() { System.Console.WriteLine("Creating a CompanyName.Car object"); CompanyName.Car myCar = new CompanyName.Car(); myCar.make = "Toyota"; System.Console.WriteLine("myCar.make = " + myCar.make); System.Console.WriteLine("Creating a DifferentCompany.Car object"); DifferentCompany.Car myOtherCar = new DifferentCompany.Car(); myOtherCar.make = "Porsche"; System.Console.WriteLine("myOtherCar.make = " + myOtherCar.make); } } |
namespace CompanyName { namespace UserInterface { public class MyClass { public void Test() { System.Console.WriteLine("UserInterface Test()"); } } } } namespace CompanyName.DatabaseAccess { public class MyClass { public void Test() { System.Console.WriteLine("DatabaseAccess Test()"); } } } class MainClass { public static void Main() { CompanyName.UserInterface.MyClass myUI = new CompanyName.UserInterface.MyClass(); CompanyName.DatabaseAccess.MyClass myDB = new CompanyName.DatabaseAccess.MyClass(); CompanyName.DatabaseAccess.MyClass myMT = new CompanyName.DatabaseAccess.MyClass(); myUI.Test(); myDB.Test(); myMT.Test(); } } |
using System; class MainClass { static void Main(string[] args) { string MyString = "Hello World"; string Path = @"c:\Program Files"; string Path2 = "c:\\Program Files"; string Name = "Joe"; } } |
using System; class MainClass { static void Main(string[] args) { string strOriginal = "Original String"; Console.WriteLine("Value of strOriginal before call: {0}", strOriginal); TryToAlterString(strOriginal); Console.WriteLine("Value of strOriginal after call: {0}", strOriginal); } static void TryToAlterString(string str) { str = "Modified string"; } } |
using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { string s1 = "This is my string."; Console.WriteLine("s1 = {0}", s1); string upperString = s1.ToUpper(); Console.WriteLine("upperString = {0}", upperString); Console.WriteLine("s1 = {0}", s1); string s2 = "My other string"; s2 = "New string value"; } } |
using System; using System.IO; using System.Text; public class MainClass { public static void Main(String[] args) { string address = String.Empty; } } |
using System; class MainClass { public static void Main() { string myString = "To be or not to be"; for (int count = 0; count < myString.Length; count++) { Console.WriteLine("myString(" + count + "] = " + myString[count]); } } } |
using System; class MainClass { public static void Main() { int result; result = String.Compare("bbc", "abc"); Console.WriteLine("String.Compare(\"bbc\", \"abc\" = " + result); result = String.Compare("abc", "bbc"); Console.WriteLine("String.Compare(\"abc\", \"bbc\" = " + result); result = String.Compare("bbc", "bbc"); Console.WriteLine("String.Compare(\"bbc\", \"bbc\" = " + result); result = String.Compare("bbc", "BBC", true); Console.WriteLine("String.Compare(\"bbc\", \"BBC\", true = " + result); result = String.Compare("bbc", "BBC", false); Console.WriteLine("String.Compare(\"bbc\", \"BBC\", false = " + result); result = String.Compare("Hello World", 6, "Goodbye World", 8, 5); Console.WriteLine("String.Compare(\"Hello World\", 6, " + "\"Goodbye World\", 8, 5) = " + result); } } |
using System; class MainClass { public static void Main() { string myString4 = String.Concat("A, ", "B"); Console.WriteLine("String.Concat(\"A, \", \"B\") = " + myString4); string myString5 = String.Concat("A, ", "B ", "and countrymen"); Console.WriteLine("String.concat(\"A, \", \"B \", " + "\"and countrymen\") = " + myString5); } } |
using System; class MainClass { public static void Main() { string myString6 = "To be, " + "or not to be"; Console.WriteLine("\"To be, \" + \"or not to be\" = " + myString6); } } |
using System; class MainClass { public static void Main() { string myString4 = "string4"; Console.WriteLine("myString4 = " + myString4); Console.WriteLine("Copying myString4 to myString7 using Copy()"); string myString7 = String.Copy(myString4); Console.WriteLine("myString7 = " + myString7); } } |
using System; class MainClass { public static void Main() { bool boolResult; string myString = "str"; string myString2 = "str2"; boolResult = String.Equals("bbc", "bbc"); Console.WriteLine("String.Equals(\"bbc\", \"bbc\") is " + boolResult); boolResult = myString.Equals(myString2); Console.WriteLine("myString.Equals(myString2) is " + boolResult); boolResult = myString == myString2; Console.WriteLine("myString == myString2 is " + boolResult); } } |
using System; class MainClass { public static void Main() { float myFloat = 1234.56789f; string myString8 = String.Format("{0, 10:f3}", myFloat); Console.WriteLine("String.Format(\"{0, 10:f3}\", myFloat) = " + myString8); } } |
using System; class MainClass { public static void Main() { string[] myStrings = { "To", "be", "or", "not", "to", "be" }; string myString9 = String.Join(".", myStrings); Console.WriteLine("myString9 = " + myString9); } } |
using System; class MainClass { public static void Main() { string[] myStrings = { "To", "be", "or", "not", "to", "be" }; string myString9 = String.Join(".", myStrings); myStrings = myString9.Split('.'); foreach (string mySplitString in myStrings) { Console.WriteLine("mySplitString = " + mySplitString); } } } |
using System; class MainClass { public static void Main() { string[] myStrings = { "To", "be", "or", "not", "to", "be" }; string myString = String.Join(".", myStrings); char[] myChars = { 'b', 'e' }; int index = myString.IndexOfAny(myChars); Console.WriteLine("'b' and 'e' occur at index " + index + " of myString"); index = myString.LastIndexOfAny(myChars); Console.WriteLine("'b' and 'e' last occur at index " + index + " of myString"); } } |
using System; class MainClass { public static void Main() { string[] myStrings = { "To", "be", "or", "not", "to", "be" }; string myString = String.Join(".", myStrings); string myString10 = myString.Insert(6, "A, "); Console.WriteLine("myString.Insert(6, \"A, \") = " + myString10); string myString11 = myString10.Remove(14, 7); Console.WriteLine("myString10.Remove(14, 7) = " + myString11); string myString12 = myString11.Replace(',', '?'); Console.WriteLine("myString11.Replace(',', '?') = " + myString12); string myString13 = myString12.Replace("to be", "Or not to be A"); Console.WriteLine("myString12.Replace(\"to be\", \"Or not to be A\") = " + myString13); } } |
using System; class MainClass { public static void Main() { string[] myStrings = { "To", "Be", "or", "not", "to", "be" }; string myString = String.Join(".", myStrings); string myString14 = '(' + myString.PadLeft(20) + ')'; Console.WriteLine("'(' + myString.PadLeft(20) + ')' = " + myString14); string myString15 = '(' + myString.PadLeft(20, '.') + ')'; Console.WriteLine("'(' + myString.PadLeft(20, '.') = " + myString15); string myString16 = '(' + myString.PadRight(20) + ')'; Console.WriteLine("'(' + myString.PadRight(20) + ')' = " + myString16); string myString17 = '(' + myString.PadRight(20, '|') + ')'; Console.WriteLine("'(' + myString.PadRight(20, '|') + ')' = " + myString17); } } |
using System; class MainClass { public static void Main() { string myString18 = '(' + " Whitespace ".Trim() + ')'; Console.WriteLine("'(' + \" Whitespace \".Trim() + ')' = " + myString18); string myString19 = '(' + " Whitespace ".TrimStart() + ')'; Console.WriteLine("'(' + \" Whitespace \".TrimStart() + ')' = " + myString19); string myString20 = '(' + " Whitespace ee".TrimEnd(new char[] {'e', ' '}) + ')'; Console.WriteLine("'(' + \" Whitespace \".TrimEnd() + ')' = " + myString20); } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { if(File.Exists("test.txt")) { string content = File.ReadAllText("test.txt"); Console.WriteLine("Current content of file:"); Console.WriteLine(content); } Console.WriteLine("Please enter new content for the file:"); string newContent = Console.ReadLine(); File.WriteAllText("test.txt", newContent); } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { if (File.Exists("test.txt")) { string content = File.ReadAllText("test.txt"); Console.WriteLine("Current content of file:"); Console.WriteLine(content); } Console.WriteLine("Please enter new content for the file:"); using (StreamWriter sw = new StreamWriter("test.txt")) { string newContent = Console.ReadLine(); while (newContent != "exit") { sw.Write(newContent + Environment.NewLine); newContent = Console.ReadLine(); } } } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { if (File.Exists("test.txt")) { File.Delete("test.txt"); if (File.Exists("test.txt") == false) { Console.WriteLine("File deleted..."); } } else { Console.WriteLine("File test.txt does not yet exist!"); } Console.ReadKey(); } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { if (Directory.Exists("testdir")) { Directory.Delete("testdir"); if (Directory.Exists("testdir") == false) Console.WriteLine("Directory deleted..."); } else Console.WriteLine("Directory testdir does not yet exist!"); } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { if (File.Exists("test.txt")) { Console.WriteLine("Please enter a new name for this file:"); string newFilename = Console.ReadLine(); if (newFilename != String.Empty) { File.Move("test.txt", newFilename); if (File.Exists(newFilename)) { Console.WriteLine("The file was renamed to " + newFilename); } } } } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { Console.WriteLine("Please enter a new name for this directory:"); string newDirName = Console.ReadLine(); if (newDirName != String.Empty) { Directory.Move("testdir", newDirName); if (Directory.Exists(newDirName)) { Console.WriteLine("The directory was renamed to " + newDirName); } } } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { Console.WriteLine("Please enter a name for the new directory:"); string newDirName = Console.ReadLine(); if (newDirName != String.Empty) { Directory.CreateDirectory(newDirName); if (Directory.Exists(newDirName)) { Console.WriteLine("The directory was created!"); } } } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); if (fi != null) Console.WriteLine(String.Format("Information about file: {0}, {1} bytes, last modified on {2} - Full path: {3}", fi.Name, fi.Length, fi.LastWriteTime, fi.FullName)); } } } |
using System; using System.IO; namespace FileHandlingArticleApp { class Program { static void Main(string[] args) { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); if (di != null) { FileInfo[] subFiles = di.GetFiles(); if (subFiles.Length > 0) { Console.WriteLine("Files:"); foreach (FileInfo subFile in subFiles) { Console.WriteLine("\t" + subFile.Name + "\t(" + subFile.Length + " bytes)"); } } } } } } |
using System; class Demo { public static int k; public int i; public void show() { Console.WriteLine("k = {0} i = {1}", k, i); } } class Test { public static void Main() { Demo a = new Demo(); a.i = 1; Demo b = new Demo(); b.i = 2; Demo.k = 4; a.show(); b.show(); } } |
using System; public class Swap { public void swap(ref int x, ref int y) { int temp = x; x = y; y = temp; } } public class Test { static void Main() { int a = 2; int b = 4; Swap hi = new Swap(); hi.swap(ref a, ref b); Console.WriteLine("a = {0}, b = {1}", a, b); } } |
using System; class Demo { public class animal { int weight; string name; public void show() { Console.WriteLine("{0} has weight {1}", name, weight); } public void my_set(int k, string z) { weight = k; name = z; } } public class tiger : animal { public tiger() { my_set(100, "tiger"); show(); } } public class lion : animal { public lion() { my_set(200, "lion"); show(); } } public static void Main() { tiger Mike = new tiger(); lion Bob = new lion(); } } |
using System; class Demo { public class Test { public void change(int k) { k = k + 2; } } public static void Main() { int i = 3; Test hi = new Test(); Console.WriteLine("Before {0}", i); hi.change(i); Console.WriteLine("After {0}", i); } } |
using System; class Demo { public class Test { public int change(int k) { return k + 2; } } public static void Main() { int i = 3; Test hi = new Test(); Console.WriteLine("Before {0}", i); Console.WriteLine("After {0}", hi.change(i)); } } |
using System; class Demo { public class Test { public void change(ref int k) { k = k + 2; } } public static void Main() { int i = 3; Test hi = new Test(); Console.WriteLine("Before {0}", i); hi.change(ref i); Console.WriteLine("After {0}", i); } } |
using System.Windows.Forms; class test : Form { public static void Main() { test Helloform = new test(); Helloform.Text = "How do you do?"; Application.Run(Helloform); } } |
using System.Windows.Forms; class test : Form { public static void Main() { test HelloForm = new test(); System.Windows.Forms.TextBox text = new System.Windows.Forms.TextBox(); text.Text = "This is a textbox"; HelloForm.Controls.Add(text); Application.Run(HelloForm); } } |
using System.Windows.Forms; class test : Form { public static void Main() { test HelloForm = new test(); HelloForm.BackColor = System.Drawing.Color.Yellow; System.Windows.Forms.CheckBox check = new System.Windows.Forms.CheckBox(); check.Text = "checkbox"; HelloForm.Controls.Add(check); Application.Run(HelloForm); } } |
'C#' 카테고리의 다른 글
[GUI] Empty Form (0) | 2010.09.19 |
---|
'Compile 강좌' 카테고리의 다른 글
[컴파일 강좌] 2강 - C++ 분할 컴파일 (0) | 2010.06.22 |
---|---|
[컴파일 강좌] 1강 - C 분할 컴파일 (0) | 2010.06.21 |
컴파일러 옵션 (0) | 2010.05.30 |
'C' 카테고리의 다른 글
itoa 대신 sprintf (0) | 2010.06.26 |
---|---|
포인터 상수 (0) | 2010.06.24 |
문자열 (0) | 2010.06.13 |
구조체 (0) | 2010.06.12 |
버블 정렬 c 0609 (0) | 2010.06.09 |
#include <stdio.h>
int main(void) {
int arr[4] = {1, 2, 3, 4};
printf("&arr = %p\n", &arr); // 0012FF54
printf("arr = %p\n", arr); // 0012FF54
printf("&arr[0] = %p\n", &arr[0]); // 0012FF54
return 0;
}
arr과 &arr 이 출력하는 메모리주소는 분명 같습니다만,
그 의미에는 미묘한 차이가 있습니다.
익히 아시고 계신 것처럼 arr은 &arr[0] 과 같은 의미이며, 그 data type은 배열의 data type입니다.
즉 arr + 1의 의미는 arr[0]에서 int형의 size만큼, 4byte 이동한 주소, &arr[1]을 의미할 수 있습니다
하지만 &arr은 그렇지 않습니다. &arr은 arr이라는 이름의 int형 4개짜리 일차원 배열의 시작주소입니다.
이것은 즉 (&arr) + 1 이 &arr[1] 을 의미하지 않음을 말합니다.
이러한 맥락에서 (&arr) + 1은 arr[0]에서 int형의 size*배열의 데이터 갯수(4) 를 곱한만큼 이동한 곳
의 주소입니다. 다음의 코드를 봐주세요.
int a[4] = {0, 1, 2, 3};
int (*pa)[4] = &a; /* 그냥 a를 쓰면 에러가 납니다 &a[0]과 &a는 의미하는 바가 달라서입니다
pa는 int형의 데이터 4개를 가지는 일차원배열을 가리키는 포인터입니다 */
pa++; /* 메모리 주소가 sizeof(int) * 4(배열데이터갯수) 만큼 이동합니다 */
printf("%d\n", (*pa)[-1]); /* pa가 가리키는 일차원 배열을 참조한 후 -1 인덱스,
즉 이는 a[3]을 의미합니다 */
출력되는 값은 물론 3입니다 :)
PS) int (*pa)[4]; /* 위에 나온대로 일차원배열을 가리키는 포인터를 선언합니다 */
int *pa[4]; /* int형의 포인터 4개를 가지는 일차원배열을 선언합니다 */
'C' 카테고리의 다른 글
itoa 대신 sprintf (0) | 2010.06.26 |
---|---|
volatile (0) | 2010.06.26 |
문자열 (0) | 2010.06.13 |
구조체 (0) | 2010.06.12 |
버블 정렬 c 0609 (0) | 2010.06.09 |
'Compile 강좌' 카테고리의 다른 글
라이브러리 (0) | 2010.06.26 |
---|---|
[컴파일 강좌] 1강 - C 분할 컴파일 (0) | 2010.06.21 |
컴파일러 옵션 (0) | 2010.05.30 |
#include <stdio.h> void swap(int* a, int* b) { int temp; temp = *a; *a = *b; *b = temp; } void disp(int a, int b) { printf("a = %d, b = %d\n", a, b); } int main() { int a = 10; int b = 30; disp(a, b); swap(&a, &b); disp(a, b); return 0; } |
void swap(int* a, int* b) { int temp; temp = *a; *a = *b; *b = temp; } |
void disp(int a, int b) { printf("a = %d, b = %d\n", a, b); } |
#include <stdio.h> #include "swap.c" #include "disp.c" int main() { int a = 10; int b = 30; disp(a, b); swap(&a, &b); disp(a, b); return 0; } |
void swap(int* a, int* b) { int temp; temp = *a; *a = *b; *b = temp; } |
#include <stdio.h> void disp(int a, int b) { printf("a = %d, b = %d\n", a, b); } |
void swap(int*, int*); void disp(int, int); int main() { int a = 10; int b = 30; disp(a, b); swap(&a, &b); disp(a, b); return 0; } |
void swap(int* a, int* b); |
void disp(int a, int b); |
#include "swap.h" #include "disp.h" int main() { int a = 10; int b = 30; disp(a, b); swap(&a, &b); disp(a, b); return 0; } |
'Compile 강좌' 카테고리의 다른 글
라이브러리 (0) | 2010.06.26 |
---|---|
[컴파일 강좌] 2강 - C++ 분할 컴파일 (0) | 2010.06.22 |
컴파일러 옵션 (0) | 2010.05.30 |
- The 'signal' attribute ensures that every processor register that gets modified during the ISR is restored to its original value when the ISR exits. This is required as the compiler cannot make any assumptions as to when the interrupt will execute, and therefore cannot optimize which processor registers require saving and which don't.
- The 'signal' attribute also forces a 'return from interrupt' instruction (RETI) to be used in place of the 'return' instruction (RET) that would otherwise be used. The AVR microcontroller disables interrupts upon entering an ISR and the RETI instruction is required to re-enable them on exiting.
Avr-gcc defines an interrupt vector as a name that the linker will use to overide the weak reset addresses in the AVR interrupt vector table. For example, the USART0 receiver interrupt on an ATmega128 is defined as:
#define USART0_RX_vect _VECTOR(18)
The _VECTOR(18) macro is expanded to:
#define USART0_RX_vect __vector_18
and so the ISR macro used to define the corresponding interrupt handler in code expands to:
void __vector_18(void) __attribute__ ((signal, __INTR_ATTRS));
and this wll compile into the assembler output as the two lines:
.global __vector_18 __vector_18:
The linker picks up the name as matching the corresponding interrupt vector table entry and makes the replacement into the vector table. Thus an interrupt with this number will arrive at the corresponding interrupt handler.
However in C++ the name is mangled early in the compile process and prevents the linking from occurring. Patch #6805 allows an interrupt handler name to be represented by a number, and while the name will be mangled as usual, the number survives for later linking. The patch provides for an optional numeric argument to the signal function. An interrupt function prototype using this system for the same USART0 receiver interrupt looks like:
void IntName(void) __attribute__ ((signal(18), __INTR_ATTRS));
The numeric signal argument is translated by this Patch into the same two assembler lines as above. The given name is still processed according to the language rules. The name is thus independent of the vector number, but the number is attached to the name. Note that for C++, by the time the signal argument is being processed the given name is mangled.
Once implemented the Patch can be used, but to be versatile it will require an additional definition for each interrupt in each processor. The current proposal is to add the new definition along with those existing. For example, the USART interrupt above for the '128 in file iom128.h will now have two lines.
#define USART0_RX_vect _VECTOR(18) #define USART0_RX_vect_num 18
The corresponding new interrupt macro for C++ interrupt declarations is defined in Interrupts.h as:
#define ISRN(name, number) void name(void) __attribute__ ((signal(number), __INTR_ATTRS));